Skip to content

Commit

Permalink
feat: update PSR message interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud committed Dec 6, 2024
1 parent 75f3d41 commit 16dff88
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 88 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"symfony/process": "^5.2"
},
"provide": {
"psr/http-message-implementation": "1.0",
"psr/http-message-implementation": "2.0",
"psr/http-factory-implementation": "1.0"
},
"scripts": {
Expand Down
24 changes: 12 additions & 12 deletions src/Psr/Message/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface MessageInterface
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion();
public function getProtocolVersion(): string;

/**
* Return an instance with the specified HTTP protocol version.
Expand All @@ -38,7 +38,7 @@ public function getProtocolVersion();
* @param string $version HTTP protocol version
* @return static
*/
public function withProtocolVersion($version);
public function withProtocolVersion(string $version): MessageInterface;

/**
* Retrieves all message header values.
Expand All @@ -65,7 +65,7 @@ public function withProtocolVersion($version);
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders();
public function getHeaders(): array;

/**
* Checks if a header exists by the given case-insensitive name.
Expand All @@ -75,7 +75,7 @@ public function getHeaders();
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader($name);
public function hasHeader(string $name): bool;

/**
* Retrieves a message header value by the given case-insensitive name.
Expand All @@ -91,7 +91,7 @@ public function hasHeader($name);
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader($name);
public function getHeader(string $name): array;

/**
* Retrieves a comma-separated string of the values for a single header.
Expand All @@ -112,7 +112,7 @@ public function getHeader($name);
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return an empty string.
*/
public function getHeaderLine($name);
public function getHeaderLine(string $name): string;

/**
* Return an instance with the provided value replacing the specified header.
Expand All @@ -129,7 +129,7 @@ public function getHeaderLine($name);
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader($name, $value);
public function withHeader(string $name, $value): MessageInterface;

/**
* Return an instance with the specified header appended with the given value.
Expand All @@ -147,7 +147,7 @@ public function withHeader($name, $value);
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader($name, $value);
public function withAddedHeader(string $name, $value): MessageInterface;

/**
* Return an instance without the specified header.
Expand All @@ -161,14 +161,14 @@ public function withAddedHeader($name, $value);
* @param string $name Case-insensitive header field name to remove.
* @return static
*/
public function withoutHeader($name);
public function withoutHeader(string $name): MessageInterface;

/**
* Gets the body of the message.
*
* @return StreamInterface Returns the body as a stream.
*/
public function getBody();
public function getBody(): StreamInterface;

/**
* Return an instance with the specified message body.
Expand All @@ -183,5 +183,5 @@ public function getBody();
* @return static
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamInterface $body);
}
public function withBody(StreamInterface $body): MessageInterface;
}
17 changes: 9 additions & 8 deletions src/Psr/Message/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface RequestInterface extends MessageInterface
*
* @return string
*/
public function getRequestTarget();
public function getRequestTarget(): string;

/**
* Return an instance with the specific request-target.
Expand All @@ -55,17 +55,18 @@ public function getRequestTarget();
*
* @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
* request-target forms allowed in request messages)
* @param mixed $requestTarget
* @param string $requestTarget
* @return static
*/
public function withRequestTarget($requestTarget);
public function withRequestTarget(string $requestTarget): RequestInterface;


/**
* Retrieves the HTTP method of the request.
*
* @return string Returns the request method.
*/
public function getMethod();
public function getMethod(): string;

/**
* Return an instance with the provided HTTP method.
Expand All @@ -82,7 +83,7 @@ public function getMethod();
* @return static
* @throws \InvalidArgumentException for invalid HTTP methods.
*/
public function withMethod($method);
public function withMethod(string $method): RequestInterface;

/**
* Retrieves the URI instance.
Expand All @@ -93,7 +94,7 @@ public function withMethod($method);
* @return UriInterface Returns a UriInterface instance
* representing the URI of the request.
*/
public function getUri();
public function getUri(): UriInterface;

/**
* Returns an instance with the provided URI.
Expand Down Expand Up @@ -125,5 +126,5 @@ public function getUri();
* @param bool $preserveHost Preserve the original state of the Host header.
* @return static
*/
public function withUri(UriInterface $uri, $preserveHost = false);
}
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface;
}
8 changes: 4 additions & 4 deletions src/Psr/Message/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface ResponseInterface extends MessageInterface
*
* @return int Status code.
*/
public function getStatusCode();
public function getStatusCode(): int;

/**
* Return an instance with the specified status code and, optionally, reason phrase.
Expand All @@ -49,7 +49,7 @@ public function getStatusCode();
* @return static
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus($code, $reasonPhrase = '');
public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface;

/**
* Gets the response reason phrase associated with the status code.
Expand All @@ -64,5 +64,5 @@ public function withStatus($code, $reasonPhrase = '');
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @return string Reason phrase; must return an empty string if none present.
*/
public function getReasonPhrase();
}
public function getReasonPhrase(): string;
}
26 changes: 13 additions & 13 deletions src/Psr/Message/ServerRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface ServerRequestInterface extends RequestInterface
*
* @return array
*/
public function getServerParams();
public function getServerParams(): array;

/**
* Retrieve cookies.
Expand All @@ -63,7 +63,7 @@ public function getServerParams();
*
* @return array
*/
public function getCookieParams();
public function getCookieParams(): array;

/**
* Return an instance with the specified cookies.
Expand All @@ -82,7 +82,7 @@ public function getCookieParams();
* @param array $cookies Array of key/value pairs representing cookies.
* @return static
*/
public function withCookieParams(array $cookies);
public function withCookieParams(array $cookies): ServerRequestInterface;

/**
* Retrieve query string arguments.
Expand All @@ -96,7 +96,7 @@ public function withCookieParams(array $cookies);
*
* @return array
*/
public function getQueryParams();
public function getQueryParams(): array;

/**
* Return an instance with the specified query string arguments.
Expand All @@ -120,7 +120,7 @@ public function getQueryParams();
* $_GET.
* @return static
*/
public function withQueryParams(array $query);
public function withQueryParams(array $query): ServerRequestInterface;

/**
* Retrieve normalized file upload data.
Expand All @@ -134,7 +134,7 @@ public function withQueryParams(array $query);
* @return array An array tree of UploadedFileInterface instances; an empty
* array MUST be returned if no data is present.
*/
public function getUploadedFiles();
public function getUploadedFiles(): array;

/**
* Create a new instance with the specified uploaded files.
Expand All @@ -147,7 +147,7 @@ public function getUploadedFiles();
* @return static
* @throws \InvalidArgumentException if an invalid structure is provided.
*/
public function withUploadedFiles(array $uploadedFiles);
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface;

/**
* Retrieve any parameters provided in the request body.
Expand Down Expand Up @@ -194,7 +194,7 @@ public function getParsedBody();
* @throws \InvalidArgumentException if an unsupported argument type is
* provided.
*/
public function withParsedBody($data);
public function withParsedBody($data): ServerRequestInterface;

/**
* Retrieve attributes derived from the request.
Expand All @@ -207,7 +207,7 @@ public function withParsedBody($data);
*
* @return array Attributes derived from the request.
*/
public function getAttributes();
public function getAttributes(): array;

/**
* Retrieve a single derived request attribute.
Expand All @@ -224,7 +224,7 @@ public function getAttributes();
* @param mixed $default Default value to return if the attribute does not exist.
* @return mixed
*/
public function getAttribute($name, $default = null);
public function getAttribute(string $name, $default = null);

/**
* Return an instance with the specified derived request attribute.
Expand All @@ -241,7 +241,7 @@ public function getAttribute($name, $default = null);
* @param mixed $value The value of the attribute.
* @return static
*/
public function withAttribute($name, $value);
public function withAttribute(string $name, $value): ServerRequestInterface;

/**
* Return an instance that removes the specified derived request attribute.
Expand All @@ -257,5 +257,5 @@ public function withAttribute($name, $value);
* @param string $name The attribute name.
* @return static
*/
public function withoutAttribute($name);
}
public function withoutAttribute(string $name): ServerRequestInterface;
}
Loading

0 comments on commit 16dff88

Please sign in to comment.