From 16ad6757d4e48a2adeb2ed10fe8eb688fc42baec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 10 Sep 2021 11:09:33 +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 --- http-message/Message.php | 27 +++++++++++++++++++++ http-message/ServerRequest.php | 29 ++--------------------- http-server/Constrict/ResponseEmitter.php | 4 ++-- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/http-message/Message.php b/http-message/Message.php index a2ea5ae9..a36693aa 100644 --- a/http-message/Message.php +++ b/http-message/Message.php @@ -3,6 +3,7 @@ namespace Protocol\Message; use JetBrains\PhpStorm\Pure; +use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; @@ -30,6 +31,13 @@ trait Message protected array $headers = []; + + /** + * @var array|null + */ + protected ?array $cookieParams = []; + + /** * @return string */ @@ -172,6 +180,25 @@ trait Message } + /** + * @return null|array + */ + public function getCookieParams(): ?array + { + return $this->cookieParams; + } + + + /** + * @param array|null $cookies + * @return static + */ + public function withCookieParams(?array $cookies): static + { + $this->cookieParams = $cookies; + return $this; + } + /** * @return StreamInterface */ diff --git a/http-message/ServerRequest.php b/http-message/ServerRequest.php index 84049122..beb2a955 100644 --- a/http-message/ServerRequest.php +++ b/http-message/ServerRequest.php @@ -26,11 +26,6 @@ class ServerRequest extends Request implements ServerRequestInterface protected ?array $serverParams; - /** - * @var array|null - */ - protected ?array $cookieParams = []; - /** * @var array|null */ @@ -103,26 +98,6 @@ class ServerRequest extends Request implements ServerRequestInterface } - /** - * @return null|array - */ - public function getCookieParams(): ?array - { - return $this->cookieParams; - } - - - /** - * @param array|null $cookies - * @return $this|ServerRequest - */ - public function withCookieParams(?array $cookies): ServerRequestInterface - { - $this->cookieParams = $cookies; - return $this; - } - - /** * @return array|null */ @@ -134,7 +109,7 @@ class ServerRequest extends Request implements ServerRequestInterface /** * @param array $query - * @return \Psr\Http\Message\ServerRequestInterface + * @return ServerRequestInterface */ public function withQueryParams(array $query): ServerRequestInterface { @@ -154,7 +129,7 @@ class ServerRequest extends Request implements ServerRequestInterface /** * @param array $uploadedFiles - * @return \Psr\Http\Message\ServerRequestInterface + * @return ServerRequestInterface */ public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface { diff --git a/http-server/Constrict/ResponseEmitter.php b/http-server/Constrict/ResponseEmitter.php index 0be500f1..fb58b76c 100644 --- a/http-server/Constrict/ResponseEmitter.php +++ b/http-server/Constrict/ResponseEmitter.php @@ -33,8 +33,8 @@ class ResponseEmitter implements Emitter $response->header($name, implode(';', $values)); } } - if (is_array($this->request->getCookieParams())) { - foreach ($this->request->getCookieParams() as $name => $cookie) { + if (is_array($emitter->getCookieParams())) { + foreach ($emitter->getCookieParams() as $name => $cookie) { $response->cookie($name, ...$cookie); } }