Implement closure support

This commit is contained in:
Johan Björk
2020-02-07 15:39:31 +01:00
parent 371b433921
commit fda4838e96
19 changed files with 161 additions and 68 deletions

View File

@@ -27,7 +27,9 @@ class RouteDocBlocker
public static function getDocBlocksFromRoute(Route $route): array
{
list($className, $methodName) = Utils::getRouteClassAndMethodNames($route);
$docBlocks = self::getCachedDocBlock($route, $className, $methodName);
$normalizedClassName = static::normalizeClassName($className);
$docBlocks = self::getCachedDocBlock($route, $normalizedClassName, $methodName);
if ($docBlocks) {
return $docBlocks;
}
@@ -38,15 +40,33 @@ class RouteDocBlocker
throw new \Exception("Error while fetching docblock for route: Class $className does not contain method $methodName");
}
$method = Utils::reflectRouteMethod([$className, $methodName]);
$docBlocks = [
'method' => new DocBlock($class->getMethod($methodName)->getDocComment() ?: ''),
'method' => new DocBlock($method->getDocComment() ?: ''),
'class' => new DocBlock($class->getDocComment() ?: ''),
];
self::cacheDocBlocks($route, $className, $methodName, $docBlocks);
self::cacheDocBlocks($route, $normalizedClassName, $methodName, $docBlocks);
return $docBlocks;
}
/**
* @param string|object $classNameOrInstance
*
* @return string
*/
protected static function normalizeClassName($classNameOrInstance): string
{
if (is_object($classNameOrInstance)) {
// route handlers are not destroyed until the script
// ends so this should be perfectly safe.
$classNameOrInstance = get_class($classNameOrInstance).'::'.spl_object_id($classNameOrInstance);
}
return $classNameOrInstance;
}
protected static function getCachedDocBlock(Route $route, string $className, string $methodName)
{
$routeId = self::getRouteCacheId($route, $className, $methodName);