diff --git a/Annotation/Route.php b/Annotation/Route.php index e1def214..1b9d3f89 100644 --- a/Annotation/Route.php +++ b/Annotation/Route.php @@ -5,7 +5,9 @@ namespace Annotation; use Closure; +use HttpServer\Route\Node; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\ConfigException; use Snowflake\Snowflake; #[\Attribute(\Attribute::TARGET_METHOD)] class Route implements IAnnotation @@ -16,26 +18,46 @@ use Snowflake\Snowflake; * Route constructor. * @param string $uri * @param string $method + * @param string|array $middleware + * @param string|array $interceptor + * @param string|array $limits + * @param string|array $after */ public function __construct( public string $uri, - public string $method + public string $method, + public string|array $middleware, + public string|array $interceptor, + public string|array $limits, + public string|array $after ) { } /** - * @param array|Closure $closure - * @return mixed + * @param array|Closure $handler + * @param array $attributes + * @return ?Node * @throws ComponentException + * @throws ConfigException */ - public function setHandler(array|Closure $closure): mixed + public function setHandler(array|Closure $handler, array $attributes): ?Node { $router = Snowflake::app()->getRouter(); // TODO: Implement setHandler() method. - return $router->addRoute($this->uri, $closure, $this->method); + $node = $router->addRoute($this->uri, $handler, $this->method); + foreach ($attributes as $name => $attribute) { + $first = 'add' . ucfirst($attribute); + + $_handler = is_array($handler) ? $handler[0] : $handler; + if (!method_exists($_handler, $first)) { + continue; + } + $node->$first($attribute); + } + return $node; }