From 0cf51a26e85dd1523f543219a10650b6324a72ab Mon Sep 17 00:00:00 2001 From: xl Date: Wed, 22 Nov 2023 17:16:10 +0800 Subject: [PATCH] eee --- src/Response.php | 14 ++++++++++++-- src/SwooleHttpResponseEmitter.php | 20 +++----------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/Response.php b/src/Response.php index 48bfa76..33febee 100644 --- a/src/Response.php +++ b/src/Response.php @@ -31,12 +31,22 @@ class Response implements ResponseInterface /** * 初始化 - * @throws */ public function __construct() { $this->contentType = \config('response.content-type', ContentType::JSON); - $this->emmit = di(\config('response.emmit', SwooleHttpResponseEmitter::class)); + $this->emmit = \config('response.emmit', SwooleHttpResponseEmitter::class); + } + + /** + * @return void + * @throws ReflectionException + */ + public function init(): void + { + if (is_string($this->emmit)) { + $this->emmit = di($this->emmit); + } } diff --git a/src/SwooleHttpResponseEmitter.php b/src/SwooleHttpResponseEmitter.php index ceb652d..289e9d9 100644 --- a/src/SwooleHttpResponseEmitter.php +++ b/src/SwooleHttpResponseEmitter.php @@ -21,21 +21,6 @@ use SplPriorityQueue; class SwooleHttpResponseEmitter implements ResponseEmitterInterface { - - /** - * @var EventProvider - */ - #[Container(EventProvider::class)] - public EventProvider $provider; - - - /** - * @var EventDispatch - */ - #[Container(EventDispatch::class)] - public EventDispatch $dispatch; - - /** * @var SplPriorityQueue */ @@ -49,9 +34,10 @@ class SwooleHttpResponseEmitter implements ResponseEmitterInterface /** - * @return void + * @param EventDispatch $dispatch + * @param EventProvider $provider */ - public function init(): void + public function __construct(readonly public EventDispatch $dispatch, readonly public EventProvider $provider) { $this->afterRequest = new OnAfterRequest(); $this->events = $this->provider->getListenersForEvent($this->afterRequest);