From f1a29fdeafa7454db8793562294ee4c14d036a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 18 Dec 2020 16:53:11 +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 | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/HttpServer/Http/Response.php b/HttpServer/Http/Response.php index bd14444d..12493998 100644 --- a/HttpServer/Http/Response.php +++ b/HttpServer/Http/Response.php @@ -210,32 +210,40 @@ class Response extends Application * @param $status * @return mixed */ - private function sendData($sendData, $status) + private function sendData($sendData, $status): mixed { $this->response->status($status); $this->response->header('Content-Type', $this->getContentType()); $this->response->header('Run-Time', $this->getRuntime()); + $this->response->end($this->headers($sendData)); + $this->response = null; + unset($this->response); + return $sendData; + } + + + /** + * @param $sendData + * @return string + */ + private function headers($sendData): string + { if (!empty($this->headers) && is_array($this->headers)) { foreach ($this->headers as $key => $header) { $this->response->header($key, $header); } $this->headers = []; } - if (empty($sendData)) { - $sendData = ''; - } - $this->response->end($sendData); - $this->response = null; - unset($this->response); - return $sendData; + return $sendData == null ? '' : $sendData; } + /** * @param $url * @param array $param * @return int */ - public function redirect($url, array $param = []) + public function redirect($url, array $param = []): int { if (!empty($param)) { $url .= '?' . http_build_query($param); @@ -251,7 +259,7 @@ class Response extends Application * @param null $response * @return mixed */ - public static function create($response = null) + public static function create($response = null): mixed { $ciResponse = Context::setContext('response', new Response()); $ciResponse->response = $response; @@ -273,7 +281,7 @@ class Response extends Application /** * @return string */ - public function getRuntime() + public function getRuntime(): string { return sprintf('%.5f', microtime(TRUE) - $this->startTime); }