From 902448213e5f333164499f4141db28c3d32cb72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sun, 16 Apr 2023 19:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Server.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Server.php b/src/Server.php index e6f6241..82e158a 100644 --- a/src/Server.php +++ b/src/Server.php @@ -16,6 +16,7 @@ use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Swoole\Http\Request; +use Kiri\Di\Inject\Service; use Swoole\Http\Response; use Kiri\Di\Inject\Container; use Kiri\Router\Constrict\ConstrictRequest; @@ -59,6 +60,13 @@ class Server implements OnRequestInterface public EventProvider $provider; + /** + * @var \Kiri\Router\Request + */ + #[Service('request')] + public RequestInterface $request; + + /** * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface @@ -68,7 +76,7 @@ class Server implements OnRequestInterface { $this->emitter = $this->container->get(HttpResponseEmitter::class); - $exception = Kiri::service()->get('request')->exception; + $exception = $this->request->exception; if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) { $exception = ExceptionHandlerDispatcher::class; } @@ -91,7 +99,7 @@ class Server implements OnRequestInterface $dispatcher = $this->router->query($request->server['request_uri'], $request->getMethod()); - $middleware = []; + $middleware = $this->request->middlewares; if (!($dispatcher instanceof Kiri\Router\Base\NotFoundController)) { $middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class);