From fe2bf5a1d914c702c7645b8e12e7d5980bea7811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 4 Aug 2021 14:56:48 +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/Http/Response.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/HttpServer/Http/Response.php b/HttpServer/Http/Response.php index 061a0a19..798a7200 100644 --- a/HttpServer/Http/Response.php +++ b/HttpServer/Http/Response.php @@ -65,23 +65,25 @@ class Response extends HttpService /** * @param $content - * @return string + * @return Response */ - public function toHtml($content): string + public function toHtml($content): static { $this->format = self::HTML; - return (string)$content; + $this->endData = (string)$content; + return $this; } /** * @param $content - * @return string|bool + * @return Response */ - public function toJson($content): string|bool + public function toJson($content): static { $this->format = self::JSON; - return json_encode($content, JSON_UNESCAPED_UNICODE); + $this->endData = json_encode($content, JSON_UNESCAPED_UNICODE); + return $this; } @@ -89,10 +91,11 @@ class Response extends HttpService * @param $content * @return mixed */ - public function toXml($content): mixed + public function toXml($content): static { $this->format = self::XML; - return $content; + $this->endData = $content; + return $this; } @@ -129,10 +132,12 @@ class Response extends HttpService /** * @param $statusCode + * @return Response */ - public function setStatusCode($statusCode) + public function setStatusCode($statusCode): static { $this->statusCode = $statusCode; + return $this; } @@ -150,9 +155,9 @@ class Response extends HttpService /** - * @param mixed $context - * @param int $statusCode - * @return bool + * @param mixed $data + * @param SResponse|null $response + * @return Response * @throws Exception */ public function getBuilder(mixed $data, SResponse $response = null): static @@ -165,8 +170,8 @@ class Response extends HttpService /** - * @param \Swoole\Http\Response|null $response - * @throws \Exception + * @param SResponse|null $response + * @throws Exception */ public function configure(SResponse $response = null): static { @@ -193,7 +198,7 @@ class Response extends HttpService * @param null $format * @return Response */ - public function setContent(mixed $content,int $statusCode = 200, $format = null): static + public function setContent(mixed $content, int $statusCode = 200, $format = null): static { $this->endData = $content; $this->setStatusCode($statusCode);