From c33a5af3776dcda5892ea499be43339b2ff298d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sun, 1 Aug 2021 15:32:28 +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 --- Server/HTTPServerListener.php | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/Server/HTTPServerListener.php b/Server/HTTPServerListener.php index 3edf7c93..699acfdb 100644 --- a/Server/HTTPServerListener.php +++ b/Server/HTTPServerListener.php @@ -3,6 +3,8 @@ namespace Server; use Exception; +use HttpServer\Http\Context; +use HttpServer\Http\Request as HSRequest; use HttpServer\Route\Router; use ReflectionException; use Snowflake\Exception\NotFindClassException; @@ -28,6 +30,8 @@ class HTTPServerListener extends Abstracts\Server private Router $router; + private \HttpServer\Http\Response $response; + /** * HTTPServerListener constructor. @@ -36,6 +40,7 @@ class HTTPServerListener extends Abstracts\Server public function __construct() { $this->router = Snowflake::getApp('router'); + $this->response = Snowflake::getApp('response'); parent::__construct(); } @@ -91,34 +96,17 @@ class HTTPServerListener extends Abstracts\Server public function onRequest(Request $request, Response $response) { try { - /** @var \HttpServer\Http\Response $sResponse */ - [$sRequest, $sResponse] = $this->request($request, $response); + Context::setContext(Response::class, $response); - $result = 'ok'; -// $result = $this->router->dispatch($sRequest); + $result = $this->router->dispatch(HSRequest::create($request)); } catch (Error | Throwable $exception) { $result = $this->router->exception($exception); } finally { - if (!isset($sResponse)) { - return; - } - $sResponse->send($result); + $this->response->send($result); } } - /** - * @param Request $request - * @param Response $response - * @return array - * @throws Exception - */ - public function request(Request $request, Response $response): array - { - return [\HttpServer\Http\Request::create($request), \HttpServer\Http\Response::create($response)]; - } - - /** * @param Server $server * @param int $fd