From cfde821d4e94a02430bc503393affe60bec21259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 28 Jan 2021 15:34:09 +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 --- HttpServer/Events/OnRequest.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index 61cf7590..a05cd1b0 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -35,6 +35,10 @@ class OnRequest extends Callback */ public function onHandler(Request $request, Response $response): mixed { + defer(function () use ($request) { + write(Json::encode(get_object_vars($request)), 'request'); + fire(Event::EVENT_AFTER_REQUEST); + }); try { [$req, $rep] = static::create($request, $response); if ($req->is('favicon.ico')) { @@ -46,9 +50,6 @@ class OnRequest extends Callback return \send($exception->getMessage(), $exception->getCode()); } return $this->sendErrorMessage($exception); - } finally { - write(Json::encode(get_object_vars($request)), 'request'); - $this->onAfter(); } } @@ -66,15 +67,6 @@ class OnRequest extends Callback } - /** - * @throws ComponentException - */ - public function onAfter() - { - fire(Event::EVENT_AFTER_REQUEST); - } - - /** * @param $response * @throws Exception