diff --git a/src/ObjectReflection.php b/src/ObjectReflection.php index 4c654d2..883ad0c 100644 --- a/src/ObjectReflection.php +++ b/src/ObjectReflection.php @@ -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; } diff --git a/src/Route/Attribute/Object/Route.php b/src/Route/Attribute/Object/Route.php index c185a6a..d00b427 100644 --- a/src/Route/Attribute/Object/Route.php +++ b/src/Route/Attribute/Object/Route.php @@ -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 diff --git a/src/Route/RouteFetcher.php b/src/Route/RouteFetcher.php index a635b0e..4ee34a5 100644 --- a/src/Route/RouteFetcher.php +++ b/src/Route/RouteFetcher.php @@ -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;