From b16348927a80171873a563d9ad6c0e93a6160e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sun, 16 Apr 2023 03:30:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Constrict/ConstrictRequest.php | 41 +----------------------- src/Constrict/ConstrictResponse.php | 22 ------------- src/Constrict/Message.php | 48 +++++++++++++++++++++++++++++ src/Server.php | 2 +- 4 files changed, 50 insertions(+), 63 deletions(-) diff --git a/src/Constrict/ConstrictRequest.php b/src/Constrict/ConstrictRequest.php index dd75819..9ced6d7 100644 --- a/src/Constrict/ConstrictRequest.php +++ b/src/Constrict/ConstrictRequest.php @@ -29,7 +29,7 @@ class ConstrictRequest extends Message implements RequestInterface, ServerReques private array $files = []; private array $queryParams = []; - private array $cookieParams = []; + private array $serverParams = []; @@ -211,45 +211,6 @@ class ConstrictRequest extends Message implements RequestInterface, ServerReques return $this->serverParams = []; } - /** - * Retrieve cookies. - * - * Retrieves cookies sent by the client to the server. - * - * The data MUST be compatible with the structure of the $_COOKIE - * superglobal. - * - * @return array - */ - public function getCookieParams(): array - { - // TODO: Implement getCookieParams() method. - return $this->cookieParams; - } - - /** - * Return an instance with the specified cookies. - * - * The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST - * be compatible with the structure of $_COOKIE. Typically, this data will - * be injected at instantiation. - * - * This method MUST NOT update the related Cookie header of the request - * instance, nor related values in the server params. - * - * This method MUST be implemented in such a way as to retain the - * immutability of the message, and MUST return an instance that has the - * updated cookie values. - * - * @param array $cookies Array of key/value pairs representing cookies. - * @return static - */ - public function withCookieParams(array $cookies): static - { - // TODO: Implement withCookieParams() method. - $this->cookieParams = $cookies; - return $this; - } /** * Return an instance with the specified cookies. diff --git a/src/Constrict/ConstrictResponse.php b/src/Constrict/ConstrictResponse.php index 3560474..d158657 100644 --- a/src/Constrict/ConstrictResponse.php +++ b/src/Constrict/ConstrictResponse.php @@ -14,7 +14,6 @@ class ConstrictResponse extends Message implements ResponseInterface private string $reasonPhrase; - private array $cookieParams; /** @@ -90,27 +89,6 @@ class ConstrictResponse extends Message implements ResponseInterface - /** - * @param array $cookies - * @return ResponseInterface - */ - public function withCookieParams(array $cookies): static - { - $this->cookieParams = $cookies; - return $this; - } - - - /** - * @return array - */ - public function getCookieParams(): array - { - return $this->cookieParams; - } - - - /** * @param object $response * @return void diff --git a/src/Constrict/Message.php b/src/Constrict/Message.php index 1e28f76..b68a066 100644 --- a/src/Constrict/Message.php +++ b/src/Constrict/Message.php @@ -27,6 +27,54 @@ class Message implements MessageInterface */ private StreamInterface $stream; + /** + * @var array + */ + private array $cookieParams = []; + + + + /** + * Retrieve cookies. + * + * Retrieves cookies sent by the client to the server. + * + * The data MUST be compatible with the structure of the $_COOKIE + * superglobal. + * + * @return array + */ + public function getCookieParams(): array + { + // TODO: Implement getCookieParams() method. + return $this->cookieParams; + } + + + /** + * Return an instance with the specified cookies. + * + * The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST + * be compatible with the structure of $_COOKIE. Typically, this data will + * be injected at instantiation. + * + * This method MUST NOT update the related Cookie header of the request + * instance, nor related values in the server params. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * updated cookie values. + * + * @param array $cookies Array of key/value pairs representing cookies. + * @return static + */ + public function withCookieParams(array $cookies): static + { + // TODO: Implement withCookieParams() method. + $this->cookieParams = $cookies; + return $this; + } + /** * Retrieves the HTTP protocol version as a string. diff --git a/src/Server.php b/src/Server.php index b4bb074..8bd73fb 100644 --- a/src/Server.php +++ b/src/Server.php @@ -114,7 +114,7 @@ class Server implements OnRequestInterface /** @var ConstrictResponse $PsrResponse */ $PsrResponse = Context::set(ResponseInterface::class, new ConstrictResponse()); - $PsrResponse->withContentType($response->contentType)->withCookieParams($cookie); + $PsrResponse->withContentType($response->contentType); $serverRequest = (new ConstrictRequest())->withDataHeaders($request->getData()) ->withUri(Uri::parse($request))