Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PSR-7 version 2.0 #289

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@
"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"
},
"require-dev": {
"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",
"phpunit/phpunit": "^9.6",
"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": {
Expand Down
10 changes: 5 additions & 5 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -346,7 +347,7 @@ public function withAttribute($name, $value)
* {@inheritdoc}
* @return static
*/
public function withoutAttribute($name)
public function withoutAttribute($name): ServerRequestInterface
{
$clone = clone $this;

Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function read($length): string
* {@inheritdoc}
* @return int
*/
public function write($string)
public function write($string): int
{
$written = false;

Expand Down
2 changes: 1 addition & 1 deletion src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading