From 1582c0c2410267415d1a2fb4fdddaab555f7d61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 3 Nov 2023 17:44:38 +0800 Subject: [PATCH] eee --- src/Format/ArrayFormat.php | 11 +++++++++-- src/Format/MixedFormat.php | 14 +++++++++++--- src/Format/OtherFormat.php | 9 ++++++++- src/Format/VoidFormat.php | 11 ++++++++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Format/ArrayFormat.php b/src/Format/ArrayFormat.php index f995501..663a1af 100644 --- a/src/Format/ArrayFormat.php +++ b/src/Format/ArrayFormat.php @@ -2,6 +2,7 @@ namespace Kiri\Router\Format; +use Kiri\Di\Inject\Container; use Kiri\Router\Constrict\Stream; use Psr\Http\Message\ResponseInterface; @@ -9,14 +10,20 @@ class ArrayFormat implements IFormat { + /** + * @var ResponseInterface + */ + #[Container(ResponseInterface::class)] + public ResponseInterface $response; + + /** * @param $result * @return ResponseInterface */ public function call($result): ResponseInterface { - $result = json_encode($result, JSON_UNESCAPED_UNICODE); - return \response()->withBody(new Stream($result)); + return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE))); } diff --git a/src/Format/MixedFormat.php b/src/Format/MixedFormat.php index 1d65d7a..910892b 100644 --- a/src/Format/MixedFormat.php +++ b/src/Format/MixedFormat.php @@ -2,6 +2,7 @@ namespace Kiri\Router\Format; +use Kiri\Di\Inject\Container; use Kiri\Router\Constrict\Stream; use Kiri\Router\ContentType; use Psr\Http\Message\ResponseInterface; @@ -9,6 +10,13 @@ use Psr\Http\Message\ResponseInterface; class MixedFormat implements IFormat { + /** + * @var ResponseInterface + */ + #[Container(ResponseInterface::class)] + public ResponseInterface $response; + + /** * @param mixed $result @@ -17,12 +25,12 @@ class MixedFormat implements IFormat public function call(mixed $result): ResponseInterface { if (is_object($result)) { - return \response()->withBody(new Stream('[object]')); + return $this->response->withBody(new Stream('[object]')); } if (is_array($result)) { - return \response()->withContentType(ContentType::JSON)->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE))); + return $this->response->withContentType(ContentType::JSON)->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE))); } else { - return \response()->withBody(new Stream((string)$result)); + return $this->response->withBody(new Stream((string)$result)); } } diff --git a/src/Format/OtherFormat.php b/src/Format/OtherFormat.php index 9059324..f77d948 100644 --- a/src/Format/OtherFormat.php +++ b/src/Format/OtherFormat.php @@ -2,12 +2,19 @@ namespace Kiri\Router\Format; +use Kiri\Di\Inject\Container; use Kiri\Router\Constrict\Stream; use Psr\Http\Message\ResponseInterface; class OtherFormat implements IFormat { + /** + * @var ResponseInterface + */ + #[Container(ResponseInterface::class)] + public ResponseInterface $response; + /** * @param mixed $result @@ -15,7 +22,7 @@ class OtherFormat implements IFormat */ public function call(mixed $result): ResponseInterface { - return \response()->withBody(new Stream($result)); + return $this->response->withBody(new Stream($result)); } diff --git a/src/Format/VoidFormat.php b/src/Format/VoidFormat.php index c969789..fc88572 100644 --- a/src/Format/VoidFormat.php +++ b/src/Format/VoidFormat.php @@ -2,12 +2,21 @@ namespace Kiri\Router\Format; +use Kiri\Di\Inject\Container; use Psr\Http\Message\ResponseInterface; class VoidFormat implements IFormat { + /** + * @var ResponseInterface + */ + #[Container(ResponseInterface::class)] + public ResponseInterface $response; + + + /** * @param $result * @return ResponseInterface @@ -15,7 +24,7 @@ class VoidFormat implements IFormat public function call($result): ResponseInterface { // TODO: Implement call() method. - return response(); + return $this->response; } } \ No newline at end of file