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); + } + + }