- Added a new getRoute() method

This commit is contained in:
Dave M. 2020-10-20 19:36:23 +00:00
parent 85db84e057
commit 3f8f24a35f
3 changed files with 17 additions and 0 deletions

View File

@ -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, "/"), "/");
}
}

View File

@ -6,6 +6,8 @@ class Route implements \Notes\Annotation {
public array $methods;
public string $base = "";
public function __construct(?array $methods = null)
{
if ( $methods !== null ) {

View File

@ -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;