- Parent routes can now be loaded on-demand
This commit is contained in:
parent
eac8269c48
commit
67aa7e513d
@ -85,14 +85,15 @@ class ObjectReflection {
|
||||
public function reflectMethods(int $filter =
|
||||
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED |
|
||||
ReflectionMethod::IS_PRIVATE | ReflectionMethod::IS_STATIC |
|
||||
ReflectionMethod::IS_FINAL
|
||||
ReflectionMethod::IS_FINAL,
|
||||
bool $includeParents = false
|
||||
) : array
|
||||
{
|
||||
$list = [];
|
||||
|
||||
foreach($this->classReflection->getMethods($filter) as $method) {
|
||||
# Skipping parent's methods, we'll retrieve them in its own reflection
|
||||
if ( $method->class !== $this->classname ) {
|
||||
if ( ! $includeParents && $method->class !== $this->classname ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ class Route implements \Notes\Attribute {
|
||||
public string|array $method = [ "GET", "POST" ],
|
||||
# NULL will fallback on nearest base
|
||||
public null|string $base = null,
|
||||
public null|bool $inheritRoutes = null, # true or false will skip others attribute from parents after, null = skipped for this one.
|
||||
){}
|
||||
|
||||
public function getBase() : ?string
|
||||
|
||||
@ -92,11 +92,13 @@ class RouteFetcher {
|
||||
$base = null;
|
||||
$class = $this->generateClassname($file->getBasename(".php"), $namespace);
|
||||
$methods = null;
|
||||
$inheritRoutes = null;
|
||||
|
||||
$objectResolver = new ObjectResolver($class, $this->cache);
|
||||
|
||||
if ( isset($attributes['object']) ) {
|
||||
|
||||
# Also loading Routes attribute from parent classes
|
||||
$objects = $objectResolver->reflectedClass->getClassAttributeListFromClassname($attributes['object'], true, false);
|
||||
|
||||
foreach($objects as $object) {
|
||||
@ -104,12 +106,13 @@ class RouteFetcher {
|
||||
$methods ??= (array) $object->method;
|
||||
}
|
||||
|
||||
$inheritRoutes ??= $object->inheritRoutes;
|
||||
$base ??= $object->base ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset($attributes['method']) ) {
|
||||
$routeList = $objectResolver->reflectedClass->getMethodAttributeListFromClassname( $attributes['method'], false, false );
|
||||
$routeList = $objectResolver->reflectedClass->getMethodAttributeListFromClassname( $attributes['method'], (bool) $inheritRoutes, false );
|
||||
|
||||
foreach($routeList as $func => $routes) {
|
||||
if (is_array($routes)) {
|
||||
@ -118,6 +121,7 @@ class RouteFetcher {
|
||||
if ($route instanceof \Notes\Route\Attribute\Method\Route) {
|
||||
$route->base = $route->base ?: $base;
|
||||
}
|
||||
|
||||
$route->class = $class;
|
||||
$route->classMethod = $func;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user