This commit is contained in:
2021-08-04 14:56:48 +08:00
parent 07e3f3f1e3
commit fe2bf5a1d9
+19 -14
View File
@@ -65,23 +65,25 @@ class Response extends HttpService
/** /**
* @param $content * @param $content
* @return string * @return Response
*/ */
public function toHtml($content): string public function toHtml($content): static
{ {
$this->format = self::HTML; $this->format = self::HTML;
return (string)$content; $this->endData = (string)$content;
return $this;
} }
/** /**
* @param $content * @param $content
* @return string|bool * @return Response
*/ */
public function toJson($content): string|bool public function toJson($content): static
{ {
$this->format = self::JSON; $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 * @param $content
* @return mixed * @return mixed
*/ */
public function toXml($content): mixed public function toXml($content): static
{ {
$this->format = self::XML; $this->format = self::XML;
return $content; $this->endData = $content;
return $this;
} }
@@ -129,10 +132,12 @@ class Response extends HttpService
/** /**
* @param $statusCode * @param $statusCode
* @return Response
*/ */
public function setStatusCode($statusCode) public function setStatusCode($statusCode): static
{ {
$this->statusCode = $statusCode; $this->statusCode = $statusCode;
return $this;
} }
@@ -150,9 +155,9 @@ class Response extends HttpService
/** /**
* @param mixed $context * @param mixed $data
* @param int $statusCode * @param SResponse|null $response
* @return bool * @return Response
* @throws Exception * @throws Exception
*/ */
public function getBuilder(mixed $data, SResponse $response = null): static public function getBuilder(mixed $data, SResponse $response = null): static
@@ -165,8 +170,8 @@ class Response extends HttpService
/** /**
* @param \Swoole\Http\Response|null $response * @param SResponse|null $response
* @throws \Exception * @throws Exception
*/ */
public function configure(SResponse $response = null): static public function configure(SResponse $response = null): static
{ {