From ea3eacdb841b8f875fe1e10f42cd987381e95209 Mon Sep 17 00:00:00 2001 From: whwyy Date: Tue, 30 Dec 2025 20:21:44 +0800 Subject: [PATCH] eee --- src/Router.php | 14 +++++++++----- src/RouterCollector.php | 16 +++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Router.php b/src/Router.php index feb8086..43bb0dd 100644 --- a/src/Router.php +++ b/src/Router.php @@ -37,7 +37,7 @@ class Router /** - * @param string $name + * @param string $name * @param Closure $closure */ public static function addServer(string $name, Closure $closure): void @@ -150,8 +150,8 @@ class Router /** * @param array|RequestMethod $methods - * @param string $route - * @param string|array $handler + * @param string $route + * @param string|array $handler */ public static function addRoute(array|RequestMethod $methods, string $route, string|array $handler): void { @@ -164,7 +164,7 @@ class Router /** - * @param array $config + * @param array $config * @param Closure $closure * * @throws @@ -211,11 +211,15 @@ class Router foreach ($router->getMethods() as $name => $method) { $middlewares = $method->getMiddlewares(); $validator = MiddlewareManager::getValidator($method->getClass(), $method->getMethod()); + + + var_dump(sprintf("%s::%s(%s)", $method->getClass(), $method->getMethod(), json_encode($middlewares, JSON_UNESCAPED_UNICODE))); + + if (!is_null($validator)) { array_unshift($middlewares, new ValidatorMiddleware(di(ResponseInterface::class), $method->getClass(), $method->getMethod())); } -// var_dump(sprintf("%s::%s(%s)",$method->getClass(), $method->getMethod(), json_encode($middlewares,JSON_UNESCAPED_UNICODE))); $router->setHttpHandler($name, new HttpRequestHandler($middlewares, $method)); } } diff --git a/src/RouterCollector.php b/src/RouterCollector.php index 32601f7..dacc9a2 100644 --- a/src/RouterCollector.php +++ b/src/RouterCollector.php @@ -206,10 +206,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate public function register(string $path, string $method, Handler $handler): void { $this->methods[$method . '_' . $path] = $handler; - $middlewares = $this->registerMiddleware($handler->getClass(), $handler->getMethod()); - if (count($middlewares) > 0) { - $handler->setMiddlewares($middlewares); - } + $handler->setMiddlewares($this->registerMiddleware($handler->getClass(), $handler->getMethod())); } @@ -229,7 +226,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate $middlewares = array_column($this->groupTack, 'middleware'); $response = $this->appendMiddleware($response, $middlewares); - $reflect = \Kiri::getDi()->getReflectionClass($class); + $reflect = \Kiri::getDi()->getReflectionClass($class); $attributes = $reflect->getMethod($method)->getAttributes(Annotate\Middleware::class); foreach ($attributes as $attribute) { @@ -239,18 +236,15 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate $data = $instance->middleware; if (is_string($data)) { $data = [$data]; - } + } - foreach ($data as $middleware) { + foreach ($data as $middleware) { if (!in_array($middleware, $response)) { $response[] = $middleware; } } } - - var_dump($class.'::'.$method. '(' . json_encode($response, JSON_UNESCAPED_UNICODE) . ')'); - - return $response; + return $response; }