diff --git a/src/Attribute/Method/Route.php b/src/Attribute/Method/Route.php index 8388c1f..3452b7b 100644 --- a/src/Attribute/Method/Route.php +++ b/src/Attribute/Method/Route.php @@ -2,11 +2,11 @@ namespace Notes\Route\Attribute\Method; -#[\Attribute] +#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] class Route implements \Notes\Attribute { public function __construct( - public string $name, public string $route, + public string $name, public string|array $method = [ "GET", "POST" ], public string $base = "", public ? string $class = null, diff --git a/src/Attribute/Object/Route.php b/src/Attribute/Object/Route.php index c193839..1dceb79 100644 --- a/src/Attribute/Object/Route.php +++ b/src/Attribute/Object/Route.php @@ -2,7 +2,7 @@ namespace Notes\Route\Attribute\Object; -#[\Attribute] +#[\Attribute(\Attribute::TARGET_CLASS)] class Route implements \Notes\Annotation { public function __construct( public string|array $method = [ "GET", "POST" ], diff --git a/src/RouteFetcher.php b/src/RouteFetcher.php index 704b43f..5a884de 100644 --- a/src/RouteFetcher.php +++ b/src/RouteFetcher.php @@ -1,5 +1,6 @@ cache = $cache; @@ -45,8 +43,6 @@ class RouteFetcher { 'method' => [ Annotation\Method\Route::class ], ]; } - - $this->forceCacheWrite = $forceCacheWrite; } public function addFolder($folder) : void @@ -97,19 +93,21 @@ class RouteFetcher { $class = $this->generateClassname($file->getBasename(".php"), $namespace); $methods = $this->defaultMethods; - $objectResolver = new ObjectResolver($class, true, true, false, true); + $objectResolver = new ObjectResolver($class, true, true, false, true, $this->cache); if ( isset($annotations['object']) ) { $object = $objectResolver->getAttributeFromClassname($annotations['object'], false) ?: $objectResolver->getAnnotationFromClassname($annotations['object'], false); - if ( $object->methods ?? false ) { - $methods = $object->methods; - } - elseif ($object->method ?? false ) { - $methods = (array) $object->method; - } + if ($object) { + if ( $object->methods ?? false ) { + $methods = $object->methods; + } + elseif ($object->method ?? false ) { + $methods = (array) $object->method; + } - $base = $object->base ?? ""; + $base = $object->base ?? ""; + } } if ( isset($annotations['method']) ) { @@ -145,21 +143,4 @@ class RouteFetcher { { return "\\$namespace\\$file"; } - - protected function handleCaching(string $key, callable $callback, null|int|\DateInterval $ttl = null) : mixed - { - static $internalCache = []; - - if ( isset($internalCache[$key]) ) { - return $internalCache[$key]; - } - - if ($this->forceCacheWrite || null === ( $internalCache[$key] = $this->cache->get($key) )) { - $internalCache[$key] = call_user_func($callback); - - $this->cache->set($key, $internalCache[$key], $ttl); - } - - return $internalCache[$key]; - } }