This commit is contained in:
2021-09-18 10:50:59 +08:00
parent e71d8e94d7
commit 6ffebb0950
+18 -5
View File
@@ -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);
}
}