This commit is contained in:
2021-09-18 10:38:38 +08:00
parent d0e9f834d4
commit 1f34eb6675
7 changed files with 125 additions and 78 deletions
+7 -2
View File
@@ -2,11 +2,12 @@
namespace Http\Handler\Abstracts;
use Http\Handler\Handler as CHl;
use Kiri\Kiri;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Http\Handler\Handler as CHl;
abstract class Handler implements RequestHandlerInterface
@@ -33,7 +34,11 @@ abstract class Handler implements RequestHandlerInterface
protected function execute(ServerRequestInterface $request): ResponseInterface
{
if (empty($this->middlewares) || !isset($this->middlewares[$this->offset])) {
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);
}
$middleware = $this->middlewares[$this->offset];
+4 -4
View File
@@ -13,11 +13,11 @@ class HandlerManager
/**
* @param $path
* @param $method
* @param $handler
* @param string $path
* @param string $method
* @param \Http\Handler\Handler|Closure $handler
*/
public static function add($path, $method, $handler)
public static function add(string $path, string $method, \Http\Handler\Handler|Closure $handler)
{
if (!isset(static::$handlers[$path])) {
static::$handlers[$path] = [];