This commit is contained in:
2021-10-28 14:02:25 +08:00
parent a55f6fc064
commit ab451a27b3
2 changed files with 12 additions and 11 deletions
+7 -1
View File
@@ -58,7 +58,13 @@ abstract class Handler implements RequestHandlerInterface
*/
public function dispatcher(ServerRequestInterface $request): mixed
{
$response = call_user_func($this->handler->callback, ...$this->handler->params);
if (!empty($this->handler->_aspect)) {
$this->handler->_aspect->before();
$response = $this->handler->_aspect->invoke($this->handler->callback, $this->handler->params);
$this->handler->_aspect->after($response);
} else {
$response = call_user_func($this->handler->callback, ...$this->handler->params);
}
if (!($response instanceof ResponseInterface)) {
$response = $this->transferToResponse($response);
}
+5 -10
View File
@@ -7,6 +7,7 @@ use Closure;
use Http\Handler\Abstracts\MiddlewareManager;
use Kiri\Di\NoteManager;
use Kiri\Events\EventProvider;
use Kiri\IAspect;
use Kiri\Kiri;
use Server\Events\OnAfterWorkerStart;
@@ -23,6 +24,9 @@ class Handler
public ?array $params = [];
public IAspect $_aspect;
public ?array $_middlewares = [];
@@ -65,16 +69,7 @@ class Handler
if (empty($aspect)) {
return;
}
$callback = $this->callback;
$params = $this->params;
$this->params = [];
$this->callback = static function () use ($aspect, $callback, $params) {
$aspect->before();
$result = $aspect->invoke($callback, $params);
$aspect->after($result);
return $result;
};
$this->_aspect = $aspect;
}