diff --git a/src/Annotation/Method/Route.php b/src/Annotation/Method/Route.php index aec0959..a6b6388 100644 --- a/src/Annotation/Method/Route.php +++ b/src/Annotation/Method/Route.php @@ -16,6 +16,8 @@ class Route implements \Notes\Annotation { public string $method; + public string $base; + public array $methods; public string $class; @@ -36,4 +38,12 @@ class Route implements \Notes\Annotation { $this->method = $method; } } + + public function getRoute() : string + { + return "/" . trim(isset($this->base) ? + "/" . trim($this->base, "/") . "/" . ltrim($this->route, "/") + : + "/" . ltrim($this->route, "/"), "/"); + } } diff --git a/src/Annotation/Object/Route.php b/src/Annotation/Object/Route.php index 61d4550..446c0e1 100644 --- a/src/Annotation/Object/Route.php +++ b/src/Annotation/Object/Route.php @@ -6,6 +6,8 @@ class Route implements \Notes\Annotation { public array $methods; + public string $base = ""; + public function __construct(?array $methods = null) { if ( $methods !== null ) { diff --git a/src/RouteFetcher.php b/src/RouteFetcher.php index ddc793c..14c4328 100644 --- a/src/RouteFetcher.php +++ b/src/RouteFetcher.php @@ -64,6 +64,7 @@ class RouteFetcher { public function compile() : Generator { foreach($this->scan() as $namespace => $file) { + $base = ""; $class = $this->generateClassname($file->getBasename(".php"), $namespace); $methods = $this->defaultMethods; @@ -74,11 +75,15 @@ class RouteFetcher { if ( $object->methods ?? false ) { $methods = $object->methods; } + + $base = $object->base ?? ""; } $routeList = $objectResolver->getAnnotationListFromClassname( $this->annotations['method'] ); foreach($routeList as $func => $route) { + + $route->base = $base; $route->class = $class; $route->classMethod = $func;