From 6ffebb09506623087c297f8b91ff166b2271c036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sat, 18 Sep 2021 10:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-handler/Abstracts/Handler.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/http-handler/Abstracts/Handler.php b/http-handler/Abstracts/Handler.php index 4e33acdf..00f71120 100644 --- a/http-handler/Abstracts/Handler.php +++ b/http-handler/Abstracts/Handler.php @@ -34,11 +34,7 @@ abstract class Handler implements RequestHandlerInterface protected function execute(ServerRequestInterface $request): ResponseInterface { if (empty($this->middlewares) || !isset($this->middlewares[$this->offset])) { - [$controller, $action] = $this->handler->callback; - - $controller = Kiri::getDi()->get($controller); - - return call_user_func([$controller, $action], ...$this->handler->params); + return $this->dispatcher(); } $middleware = $this->middlewares[$this->offset]; @@ -52,4 +48,21 @@ abstract class Handler implements RequestHandlerInterface } + /** + * @return mixed + */ + protected function dispatcher(): mixed + { + if ($this->handler->callback instanceof \Closure) { + return call_user_func($this->handler->callback, ...$this->handler->params); + + } + [$controller, $action] = $this->handler->callback; + + $controller = Kiri::getDi()->get($controller); + + return call_user_func([$controller, $action], ...$this->handler->params); + } + + }