diff --git a/Annotation/Annotation.php b/Annotation/Annotation.php index f83d1bdc..4300f508 100644 --- a/Annotation/Annotation.php +++ b/Annotation/Annotation.php @@ -5,6 +5,7 @@ namespace Annotation; use Exception; +use JetBrains\PhpStorm\Pure; use ReflectionAttribute; use ReflectionClass; use ReflectionException; @@ -67,19 +68,6 @@ class Annotation extends Component } - /** - * @param string $alias - * @return array - */ - public function getAlias(string $alias = 'root'): array - { - if (!isset($this->_annotations[$alias])) { - return []; - } - return $this->_annotations[$alias]; - } - - /** * @param array $paths * @param string $namespace @@ -87,12 +75,10 @@ class Annotation extends Component * @return $this * @throws ReflectionException|NotFindPropertyException * @throws NotFindClassException + * @throws Exception */ private function scanDir(array $paths, string $namespace, string $alias): static { - if (!isset($this->_annotations[$alias])) { - $this->_annotations[$alias] = []; - } foreach ($paths as $path) { $explode = explode('/', $path); @@ -191,7 +177,7 @@ class Annotation extends Component /** * @param string $class * @return ReflectionClass|null - * @throws ReflectionException + * @throws ReflectionException|NotFindClassException */ private function reflectClass(string $class): ?ReflectionClass { @@ -213,8 +199,8 @@ class Annotation extends Component } $name = get_class($object) . '_' . $method->getName(); - if (!isset($this->_annotations[$alias][$name])) { - $this->_annotations[$alias][$name] = []; + if (!isset($this->_annotations[$name])) { + $this->_annotations[$name] = []; } $array = []; @@ -227,7 +213,7 @@ class Annotation extends Component $array[] = $class->execute([$object, $method->getName()]); } - $this->_annotations[$alias][$name][] = $array; + $this->_annotations[$name][] = $array; return []; } @@ -235,18 +221,17 @@ class Annotation extends Component /** * @param $class * @param $method - * @param string $alias * @return mixed */ - public function getAnnotationByMethod($class, $method, $alias = ''): mixed + #[Pure] public function getAnnotationByMethod($class, $method): array { - if (!isset($this->_annotations[$alias])) { - return []; - } if (is_object($class)) { $class = get_class($class); } - return $this->_annotations[$alias][$class . '_' . $method] ?? []; + if (!isset($this->_annotations[$class . '_' . $method])) { + return []; + } + return $this->_annotations[$class . '_' . $method]; } diff --git a/HttpServer/Route/Middleware.php b/HttpServer/Route/Middleware.php index e9850a01..91f904cc 100644 --- a/HttpServer/Route/Middleware.php +++ b/HttpServer/Route/Middleware.php @@ -72,10 +72,11 @@ class Middleware } [$controller, $action] = $node->handler; $attributes = Snowflake::app()->getAttributes(); - $annotation = $attributes->getAnnotationByMethod($controller, $action, 'controllers'); + $annotation = $attributes->getAnnotationByMethod($controller, $action); if (count($annotation) < 1) { return; } + var_dump(count($annotation)); foreach ($annotation as $attribute) { if ($attribute instanceof Interceptor) { $node->addInterceptor($attribute->interceptor);