diff --git a/Annotation/Route/Route.php b/Annotation/Route/Route.php index 11aca04a..8491cd3a 100644 --- a/Annotation/Route/Route.php +++ b/Annotation/Route/Route.php @@ -43,8 +43,8 @@ use Snowflake\Snowflake; // TODO: Implement setHandler() method. $router = Snowflake::app()->getRouter(); - $node = $router->addRoute($this->uri, $handler, $this->method); - $node::annotationInject($node, get_class($handler[0]), $handler[1]); + $router->addRoute($this->uri, $handler, $this->method); + return $router; } diff --git a/Annotation/Route/Socket.php b/Annotation/Route/Socket.php index 14cfd5ad..a728b08e 100644 --- a/Annotation/Route/Socket.php +++ b/Annotation/Route/Socket.php @@ -53,9 +53,7 @@ use Snowflake\Snowflake; $method = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri); - $node = $router->addRoute($method, $handler, 'sw::socket'); - - $node::annotationInject($node, get_class($handler[0]), $handler[1]); + $router->addRoute($method, $handler, 'sw::socket'); return $router; } diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index a47cd58f..0e99d061 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -79,10 +79,12 @@ class Node extends HttpService } else if ($handler != null && !is_callable($handler, true)) { $this->_error = 'Controller is con\'t exec.'; } else { - $this->handler = $handler; + [$controller, $action] = $this->handler = $handler; + + $this->annotationInject(get_class($controller), $action); } if (!empty($this->handler)) { - $this->callback = Reduce::reduce($this->createDispatch(), $this->annotation($this)); + $this->callback = Reduce::reduce($this->createDispatch(), $this->annotation()); } return $this; } @@ -100,14 +102,13 @@ class Node extends HttpService /** - * @param Node $node * @return array */ - protected function annotation(Node $node): array + protected function annotation(): array { - $middleWares = $node->getMiddleWares(); - $middleWares = $this->annotation_limit($node, $middleWares); - $middleWares = $this->annotation_interceptor($node, $middleWares); + $middleWares = $this->getMiddleWares(); + $middleWares = $this->annotation_limit($this, $middleWares); + $middleWares = $this->annotation_interceptor($this, $middleWares); return $middleWares; } @@ -315,30 +316,27 @@ class Node extends HttpService * @throws ReflectionException * @throws Exception */ - public static function annotationInject(Node $node, string $className, string $action): Node + public function annotationInject(string $className, string $action): Node { $annotation = annotation()->getMethods($className, $action); if (empty($annotation)) { - return $node; + return $this; } foreach ($annotation as $name => $attribute) { if ($attribute instanceof \Annotation\Route\Interceptor) { - $node->addInterceptor($attribute->interceptor); + $this->addInterceptor($attribute->interceptor); } if ($attribute instanceof \Annotation\Route\After) { - $node->addAfter($attribute->after); + $this->addAfter($attribute->after); } if ($attribute instanceof Middleware) { - $node->addMiddleware($attribute->middleware); + $this->addMiddleware($attribute->middleware); } if ($attribute instanceof \Annotation\Route\Limits) { - $node->addLimits($attribute->limits); + $this->addLimits($attribute->limits); } } - if (!empty($node->handler)) { - $node->callback = Reduce::reduce($node->createDispatch(), $node->annotation($node)); - } - return $node; + return $this; }