diff --git a/Annotation/Route/After.php b/Annotation/Route/After.php index 074a3698..82d1988e 100644 --- a/Annotation/Route/After.php +++ b/Annotation/Route/After.php @@ -18,6 +18,18 @@ use Snowflake\Snowflake; * Interceptor constructor. * @param \HttpServer\IInterface\After|\HttpServer\IInterface\After[] $after * @throws + * if ($object instanceof Interceptor) { + $classes[$key] = [$object, 'Interceptor']; + } + if ($object instanceof Limits) { + $classes[$key] = [$object, 'next']; + } + if ($object instanceof After) { + $classes[$key] = [$object, 'onHandler']; + } + if ($object instanceof Middleware) { + $classes[$key] = [$object, 'onHandler']; + } */ public function __construct(public string|array $after) { @@ -25,7 +37,7 @@ use Snowflake\Snowflake; $this->after = [$this->after]; } foreach ($this->after as $key => $item) { - $this->after[$key] = Snowflake::createObject($item); + $this->after[$key] = [Snowflake::createObject($item), 'onHandler']; } } diff --git a/Annotation/Route/Interceptor.php b/Annotation/Route/Interceptor.php index a0ef0448..d99af0ff 100644 --- a/Annotation/Route/Interceptor.php +++ b/Annotation/Route/Interceptor.php @@ -25,7 +25,7 @@ use Snowflake\Snowflake; $this->interceptor = [$this->interceptor]; } foreach ($this->interceptor as $key => $item) { - $this->interceptor[$key] = Snowflake::createObject($item); + $this->interceptor[$key] = [Snowflake::createObject($item), 'Interceptor']; } } diff --git a/Annotation/Route/Limits.php b/Annotation/Route/Limits.php index fd5e3080..1e0358d8 100644 --- a/Annotation/Route/Limits.php +++ b/Annotation/Route/Limits.php @@ -25,7 +25,7 @@ use Snowflake\Snowflake; $this->limits = [$this->limits]; } foreach ($this->limits as $key => $item) { - $this->limits[$key] = Snowflake::createObject($item); + $this->limits[$key] = [Snowflake::createObject($item), 'next']; } } diff --git a/Annotation/Route/Middleware.php b/Annotation/Route/Middleware.php index d2086eb4..df504e76 100644 --- a/Annotation/Route/Middleware.php +++ b/Annotation/Route/Middleware.php @@ -25,7 +25,7 @@ use Snowflake\Snowflake; $this->middleware = [$this->middleware]; } foreach ($this->middleware as $key => $item) { - $this->middleware[$key] = Snowflake::createObject($item); + $this->middleware[$key] = [Snowflake::createObject($item), 'onHandler']; } } diff --git a/Annotation/Route/Route.php b/Annotation/Route/Route.php index 2993ef79..43fb9604 100644 --- a/Annotation/Route/Route.php +++ b/Annotation/Route/Route.php @@ -15,24 +15,14 @@ use Annotation\IAnnotation; #[\Attribute(\Attribute::TARGET_METHOD)] class Route implements IAnnotation { - use \Annotation\Route\Node; - /** * Route constructor. * @param string $uri * @param string $method - * @param array|null $middleware - * @param array|null $interceptor - * @param array|null $limits - * @param array|null $after */ public function __construct( public string $uri, - public string $method, - public ?array $middleware = null, - public ?array $interceptor = null, - public ?array $limits = null, - public ?array $after = null + public string $method ) { } @@ -50,9 +40,7 @@ use Annotation\IAnnotation; $router = Snowflake::app()->getRouter(); // TODO: Implement setHandler() method. - $node = $router->addRoute($this->uri, $handler, $this->method); - - return $this->add($node); + return $router->addRoute($this->uri, $handler, $this->method); } diff --git a/Annotation/Route/Socket.php b/Annotation/Route/Socket.php index 834d6ced..8fab9f02 100644 --- a/Annotation/Route/Socket.php +++ b/Annotation/Route/Socket.php @@ -25,25 +25,14 @@ use Snowflake\Snowflake; const MESSAGE = 'MESSAGE'; const HANDSHAKE = 'HANDSHAKE'; - use \Annotation\Route\Node; - - /** * Socket constructor. * @param string $event * @param string|null $uri - * @param array|null $middleware - * @param array|null $interceptor - * @param array|null $limits - * @param array|null $after */ public function __construct( public string $event, - public ?string $uri = null, - public ?array $middleware = null, - public ?array $interceptor = null, - public ?array $limits = null, - public ?array $after = null + public ?string $uri = null ) { } @@ -63,9 +52,7 @@ use Snowflake\Snowflake; $method = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri); - $node = $router->addRoute($method, $handler, 'sw::socket'); - - return $this->add($node); + return $router->addRoute($method, $handler, 'sw::socket'); } } diff --git a/HttpServer/Route/Middleware.php b/HttpServer/Route/Middleware.php index e3b4b231..6cdee8b3 100644 --- a/HttpServer/Route/Middleware.php +++ b/HttpServer/Route/Middleware.php @@ -56,9 +56,9 @@ class Middleware public function getGenerate(Node $node): mixed { try { -// if (is_array($node->handler) && is_object($node->handler[0])) { -// $this->set_attributes($node); -// } + if (is_array($node->handler) && is_object($node->handler[0])) { + $this->set_attributes($node); + } return $node->callback = Reduce::reduce(function () use ($node) { return Dispatch::create($node->handler, func_get_args())->dispatch(); }, $this->annotation($node));