From 8318fc7b8ff388532a1a322cf0c820f4fa349476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 19 Jul 2023 16:19:49 -0300 Subject: [PATCH] Add support for PSR-7 version 2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- composer.json | 8 ++++---- src/Message.php | 10 +++++----- src/Request.php | 19 ++++++++++--------- src/Response.php | 2 +- src/Stream.php | 2 +- src/UploadedFile.php | 2 +- src/Uri.php | 14 +++++++------- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index b3f38fe..a6773e2 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "php": "^8.0", "fig/http-message-util": "^1.1.5", "psr/http-factory": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0 || ^2.0", "ralouphie/getallheaders": "^3.0", "symfony/polyfill-php80": "^1.27" }, @@ -39,7 +39,7 @@ "ext-json": "*", "adriansuter/php-autoload-override": "^1.4", "http-interop/http-factory-tests": "^0.9.0", - "php-http/psr7-integration-tests": "dev-master", + "php-http/psr7-integration-tests": "1.x-dev", "phpspec/prophecy": "^1.17", "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "^1.10", @@ -47,8 +47,8 @@ "squizlabs/php_codesniffer": "^3.7" }, "provide": { - "psr/http-message-implementation": "1.0", - "psr/http-factory-implementation": "1.0" + "psr/http-message-implementation": "^1.0 || ^2.0", + "psr/http-factory-implementation": "^1.0" }, "autoload": { "psr-4": { diff --git a/src/Message.php b/src/Message.php index 03e4123..89b3d15 100644 --- a/src/Message.php +++ b/src/Message.php @@ -67,7 +67,7 @@ public function getProtocolVersion(): string * @return static * {@inheritdoc} */ - public function withProtocolVersion($version) + public function withProtocolVersion($version): MessageInterface { if (!isset(self::$validProtocolVersions[$version])) { throw new InvalidArgumentException( @@ -119,7 +119,7 @@ public function getHeaderLine($name): string * @return static * {@inheritdoc} */ - public function withHeader($name, $value) + public function withHeader($name, $value): MessageInterface { $clone = clone $this; $clone->headers->setHeader($name, $value); @@ -135,7 +135,7 @@ public function withHeader($name, $value) * @return static * {@inheritdoc} */ - public function withAddedHeader($name, $value) + public function withAddedHeader($name, $value): MessageInterface { $clone = clone $this; $clone->headers->addHeader($name, $value); @@ -151,7 +151,7 @@ public function withAddedHeader($name, $value) * @return static * {@inheritdoc} */ - public function withoutHeader($name) + public function withoutHeader($name): MessageInterface { $clone = clone $this; $clone->headers->removeHeader($name); @@ -175,7 +175,7 @@ public function getBody(): StreamInterface * @return static * {@inheritdoc} */ - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): MessageInterface { $clone = clone $this; $clone->body = $body; diff --git a/src/Request.php b/src/Request.php index 353f860..252f5a1 100644 --- a/src/Request.php +++ b/src/Request.php @@ -11,6 +11,7 @@ namespace Slim\Psr7; use InvalidArgumentException; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UploadedFileInterface; @@ -123,7 +124,7 @@ public function getMethod(): string * {@inheritdoc} * @return static */ - public function withMethod($method) + public function withMethod($method): RequestInterface { $method = $this->filterMethod($method); $clone = clone $this; @@ -189,7 +190,7 @@ public function getRequestTarget(): string * {@inheritdoc} * @return static */ - public function withRequestTarget($requestTarget) + public function withRequestTarget($requestTarget): RequestInterface { if (!is_string($requestTarget) || preg_match('#\s#', $requestTarget)) { throw new InvalidArgumentException( @@ -215,7 +216,7 @@ public function getUri(): UriInterface * {@inheritdoc} * @return static */ - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface { $clone = clone $this; $clone->uri = $uri; @@ -245,7 +246,7 @@ public function getCookieParams(): array * {@inheritdoc} * @return static */ - public function withCookieParams(array $cookies) + public function withCookieParams(array $cookies): ServerRequestInterface { $clone = clone $this; $clone->cookies = $cookies; @@ -277,7 +278,7 @@ public function getQueryParams(): array * {@inheritdoc} * @return static */ - public function withQueryParams(array $query) + public function withQueryParams(array $query): ServerRequestInterface { $clone = clone $this; $clone->queryParams = $query; @@ -297,7 +298,7 @@ public function getUploadedFiles(): array * {@inheritdoc} * @return static */ - public function withUploadedFiles(array $uploadedFiles) + public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface { $clone = clone $this; $clone->uploadedFiles = $uploadedFiles; @@ -334,7 +335,7 @@ public function getAttribute($name, $default = null) * {@inheritdoc} * @return static */ - public function withAttribute($name, $value) + public function withAttribute($name, $value): ServerRequestInterface { $clone = clone $this; $clone->attributes[$name] = $value; @@ -346,7 +347,7 @@ public function withAttribute($name, $value) * {@inheritdoc} * @return static */ - public function withoutAttribute($name) + public function withoutAttribute($name): ServerRequestInterface { $clone = clone $this; @@ -367,7 +368,7 @@ public function getParsedBody() * {@inheritdoc} * @return static */ - public function withParsedBody($data) + public function withParsedBody($data): ServerRequestInterface { /** @var mixed $data */ if (!is_null($data) && !is_object($data) && !is_array($data)) { diff --git a/src/Response.php b/src/Response.php index c6d4c6e..980e3b5 100644 --- a/src/Response.php +++ b/src/Response.php @@ -140,7 +140,7 @@ public function getStatusCode(): int * {@inheritdoc} * @return static */ - public function withStatus($code, $reasonPhrase = '') + public function withStatus($code, $reasonPhrase = ''): ResponseInterface { $code = $this->filterStatus($code); $reasonPhrase = $this->filterReasonPhrase($reasonPhrase); diff --git a/src/Stream.php b/src/Stream.php index 9de6685..fa8e268 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -325,7 +325,7 @@ public function read($length): string * {@inheritdoc} * @return int */ - public function write($string) + public function write($string): int { $written = false; diff --git a/src/UploadedFile.php b/src/UploadedFile.php index b0c4df5..d8d6ad6 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -111,7 +111,7 @@ final public function __construct( * {@inheritdoc} * @return StreamInterface */ - public function getStream() + public function getStream(): StreamInterface { if ($this->moved) { throw new RuntimeException(sprintf('Uploaded file %s has already been moved', $this->name)); diff --git a/src/Uri.php b/src/Uri.php index 1c114bb..d589899 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -104,7 +104,7 @@ public function getScheme(): string * {@inheritdoc} * @return static */ - public function withScheme($scheme) + public function withScheme($scheme): UriInterface { $scheme = $this->filterScheme($scheme); $clone = clone $this; @@ -169,7 +169,7 @@ public function getUserInfo(): string * {@inheritdoc} * @return static */ - public function withUserInfo($user, $password = null) + public function withUserInfo($user, $password = null): UriInterface { $clone = clone $this; $clone->user = $this->filterUserInfo($user); @@ -221,7 +221,7 @@ public function getHost(): string * {@inheritdoc} * @return static */ - public function withHost($host) + public function withHost($host): UriInterface { $clone = clone $this; $clone->host = $this->filterHost($host); @@ -270,7 +270,7 @@ public function getPort(): ?int * {@inheritdoc} * @return static */ - public function withPort($port) + public function withPort($port): UriInterface { $port = $this->filterPort($port); $clone = clone $this; @@ -324,7 +324,7 @@ public function getPath(): string * {@inheritdoc} * @return static */ - public function withPath($path) + public function withPath($path): UriInterface { if (!is_string($path)) { throw new InvalidArgumentException('Uri path must be a string'); @@ -371,7 +371,7 @@ public function getQuery(): string * {@inheritdoc} * @return static */ - public function withQuery($query) + public function withQuery($query): UriInterface { $query = ltrim($this->filterQuery($query), '?'); $clone = clone $this; @@ -422,7 +422,7 @@ public function getFragment(): string * {@inheritdoc} * @return static */ - public function withFragment($fragment) + public function withFragment($fragment): UriInterface { $fragment = $this->filterFragment($fragment); $clone = clone $this;