Skip to content

Commit

Permalink
Improves Routes to make use of the scope information to find the qual…
Browse files Browse the repository at this point in the history
…ified class name
  • Loading branch information
Arul- committed Apr 13, 2014
1 parent 54554d1 commit 1aef4b6
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function addAPIClass($className,
*/
$class = new ReflectionClass($className);
$classMetadata = CommentParser::parse($class->getDocComment());
$classMetadata['scope'] = static::scope($class);
$classMetadata['scope'] = $scope = static::scope($class);
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC +
ReflectionMethod::IS_PROTECTED);
foreach ($methods as $method) {
Expand Down Expand Up @@ -84,9 +84,9 @@ public static function addAPIClass($className,
if (!isset($metadata['param'])) {
$metadata['param'] = array();
}
if (isset($metadata['return']['type']) && class_exists($metadata['return']['type'])) {
if (isset($metadata['return']['type']) && $qualified = Scope::resolve($metadata['return']['type'], $scope)) {
list($metadata['return']['type'], $metadata['return']['children']) =
static::getTypeAndModel(new ReflectionClass($metadata['return']['type']));
static::getTypeAndModel(new ReflectionClass($qualified), $scope);
}
foreach ($params as $param) {
$children = array();
Expand All @@ -112,16 +112,16 @@ public static function addAPIClass($className,
CommentParser::$embeddedDataName,
'type'
);
if ($contentType && class_exists($contentType)) {
if ($contentType && $qualified = Scope::resolve($contentType, $scope)) {
list($contentType, $children) = static::getTypeAndModel(
new ReflectionClass($contentType)
new ReflectionClass($qualified), $scope
);
}
if ($type instanceof ReflectionClass) {
list($type, $children) = static::getTypeAndModel($type);
} elseif ($type && is_string($type) && class_exists($type)) {
list($type, $children) = static::getTypeAndModel($type, $scope);
} elseif ($type && is_string($type) && $qualified = Scope::resolve($type, $scope)) {
list($type, $children)
= static::getTypeAndModel(new ReflectionClass($type));
= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
}
if (isset($type)) {
$m['type'] = $type;
Expand Down Expand Up @@ -499,13 +499,16 @@ protected static function typeMatch($type, $var)
}

/**
* Get the type and associated model
*
* @param ReflectionClass $class
* @param array $scope
*
* @return array
*
* @access protected
*/
protected static function getTypeAndModel(ReflectionClass $class)
protected static function getTypeAndModel(ReflectionClass $class, array $scope)
{
$className = $class->getName();
if (isset(static::$models[$className])) {
Expand Down Expand Up @@ -534,12 +537,15 @@ protected static function getTypeAndModel(ReflectionClass $class)
}
}
$child += array('type' => 'string', 'label' => static::label($child['name']));
if (class_exists($child['type'])) {
if ($qualified = Scope::resolve($child['type'], $scope)) {
list($child['type'], $child['children'])
= static::getTypeAndModel(new ReflectionClass($child['type']));
} elseif (($contentType = Util::nestedValue($child, CommentParser::$embeddedDataName, 'type')) && class_exists($contentType)) {
= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
} elseif (
($contentType = Util::nestedValue($child, CommentParser::$embeddedDataName, 'type')) &&
($qualified = Scope::resolve($contentType, $scope))
) {
list($child['contentType'], $child['children'])
= static::getTypeAndModel(new ReflectionClass($contentType));
= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
}
$children[$name] = $child;
}
Expand Down

0 comments on commit 1aef4b6

Please sign in to comment.