From 9dbf3f0953d6f73925ab2916f7b598e8bf857377 Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Thu, 14 May 2015 18:05:06 +0200 Subject: [PATCH 01/16] corrected malformed annotation --- src/ServerRequestInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServerRequestInterface.php b/src/ServerRequestInterface.php index 916e065..41c6a8e 100644 --- a/src/ServerRequestInterface.php +++ b/src/ServerRequestInterface.php @@ -143,7 +143,7 @@ public function getUploadedFiles(); * immutability of the message, and MUST return an instance that has the * updated body parameters. * - * @param array An array tree of UploadedFileInterface instances. + * @param array $uploadedFiles An array tree of UploadedFileInterface instances. * @return self * @throws \InvalidArgumentException if an invalid structure is provided. */ From a6764a43faa657cef3e367a66785f2fc980bdff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Wed, 3 Jun 2015 19:39:40 +0200 Subject: [PATCH 02/16] Fix: Return static instead of self --- src/MessageInterface.php | 10 +++++----- src/RequestInterface.php | 6 +++--- src/ResponseInterface.php | 2 +- src/ServerRequestInterface.php | 12 ++++++------ src/UriInterface.php | 14 +++++++------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/MessageInterface.php b/src/MessageInterface.php index 8f67a05..39e0782 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -36,7 +36,7 @@ public function getProtocolVersion(); * new protocol version. * * @param string $version HTTP protocol version - * @return self + * @return static */ public function withProtocolVersion($version); @@ -126,7 +126,7 @@ public function getHeaderLine($name); * * @param string $name Case-insensitive header field name. * @param string|string[] $value Header value(s). - * @return self + * @return static * @throws \InvalidArgumentException for invalid header names or values. */ public function withHeader($name, $value); @@ -144,7 +144,7 @@ public function withHeader($name, $value); * * @param string $name Case-insensitive header field name to add. * @param string|string[] $value Header value(s). - * @return self + * @return static * @throws \InvalidArgumentException for invalid header names or values. */ public function withAddedHeader($name, $value); @@ -159,7 +159,7 @@ public function withAddedHeader($name, $value); * the named header. * * @param string $name Case-insensitive header field name to remove. - * @return self + * @return static */ public function withoutHeader($name); @@ -180,7 +180,7 @@ public function getBody(); * new body stream. * * @param StreamInterface $body Body. - * @return self + * @return static * @throws \InvalidArgumentException When the body is not valid. */ public function withBody(StreamInterface $body); diff --git a/src/RequestInterface.php b/src/RequestInterface.php index 75c802e..40a19bd 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -56,7 +56,7 @@ public function getRequestTarget(); * @link http://tools.ietf.org/html/rfc7230#section-2.7 (for the various * request-target forms allowed in request messages) * @param mixed $requestTarget - * @return self + * @return static */ public function withRequestTarget($requestTarget); @@ -79,7 +79,7 @@ public function getMethod(); * changed request method. * * @param string $method Case-sensitive method. - * @return self + * @return static * @throws \InvalidArgumentException for invalid HTTP methods. */ public function withMethod($method); @@ -123,7 +123,7 @@ public function getUri(); * @link http://tools.ietf.org/html/rfc3986#section-4.3 * @param UriInterface $uri New request URI to use. * @param bool $preserveHost Preserve the original state of the Host header. - * @return self + * @return static */ public function withUri(UriInterface $uri, $preserveHost = false); } diff --git a/src/ResponseInterface.php b/src/ResponseInterface.php index 6724809..c306514 100644 --- a/src/ResponseInterface.php +++ b/src/ResponseInterface.php @@ -46,7 +46,7 @@ public function getStatusCode(); * @param string $reasonPhrase The reason phrase to use with the * provided status code; if none is provided, implementations MAY * use the defaults as suggested in the HTTP specification. - * @return self + * @return static * @throws \InvalidArgumentException For invalid status code arguments. */ public function withStatus($code, $reasonPhrase = ''); diff --git a/src/ServerRequestInterface.php b/src/ServerRequestInterface.php index 916e065..ff5395d 100644 --- a/src/ServerRequestInterface.php +++ b/src/ServerRequestInterface.php @@ -80,7 +80,7 @@ public function getCookieParams(); * updated cookie values. * * @param array $cookies Array of key/value pairs representing cookies. - * @return self + * @return static */ public function withCookieParams(array $cookies); @@ -118,7 +118,7 @@ public function getQueryParams(); * * @param array $query Array of query string arguments, typically from * $_GET. - * @return self + * @return static */ public function withQueryParams(array $query); @@ -144,7 +144,7 @@ public function getUploadedFiles(); * updated body parameters. * * @param array An array tree of UploadedFileInterface instances. - * @return self + * @return static * @throws \InvalidArgumentException if an invalid structure is provided. */ public function withUploadedFiles(array $uploadedFiles); @@ -190,7 +190,7 @@ public function getParsedBody(); * * @param null|array|object $data The deserialized body data. This will * typically be in an array or object. - * @return self + * @return static * @throws \InvalidArgumentException if an unsupported argument type is * provided. */ @@ -239,7 +239,7 @@ public function getAttribute($name, $default = null); * @see getAttributes() * @param string $name The attribute name. * @param mixed $value The value of the attribute. - * @return self + * @return static */ public function withAttribute($name, $value); @@ -255,7 +255,7 @@ public function withAttribute($name, $value); * * @see getAttributes() * @param string $name The attribute name. - * @return self + * @return static */ public function withoutAttribute($name); } diff --git a/src/UriInterface.php b/src/UriInterface.php index 1ff5bf0..9d7ab9e 100644 --- a/src/UriInterface.php +++ b/src/UriInterface.php @@ -185,7 +185,7 @@ public function getFragment(); * An empty scheme is equivalent to removing the scheme. * * @param string $scheme The scheme to use with the new instance. - * @return self A new instance with the specified scheme. + * @return static A new instance with the specified scheme. * @throws \InvalidArgumentException for invalid or unsupported schemes. */ public function withScheme($scheme); @@ -202,7 +202,7 @@ public function withScheme($scheme); * * @param string $user The user name to use for authority. * @param null|string $password The password associated with $user. - * @return self A new instance with the specified user information. + * @return static A new instance with the specified user information. */ public function withUserInfo($user, $password = null); @@ -215,7 +215,7 @@ public function withUserInfo($user, $password = null); * An empty host value is equivalent to removing the host. * * @param string $host The hostname to use with the new instance. - * @return self A new instance with the specified host. + * @return static A new instance with the specified host. * @throws \InvalidArgumentException for invalid hostnames. */ public function withHost($host); @@ -234,7 +234,7 @@ public function withHost($host); * * @param null|int $port The port to use with the new instance; a null value * removes the port information. - * @return self A new instance with the specified port. + * @return static A new instance with the specified port. * @throws \InvalidArgumentException for invalid ports. */ public function withPort($port); @@ -258,7 +258,7 @@ public function withPort($port); * Implementations ensure the correct encoding as outlined in getPath(). * * @param string $path The path to use with the new instance. - * @return self A new instance with the specified path. + * @return static A new instance with the specified path. * @throws \InvalidArgumentException for invalid paths. */ public function withPath($path); @@ -275,7 +275,7 @@ public function withPath($path); * An empty query string value is equivalent to removing the query string. * * @param string $query The query string to use with the new instance. - * @return self A new instance with the specified query string. + * @return static A new instance with the specified query string. * @throws \InvalidArgumentException for invalid query strings. */ public function withQuery($query); @@ -292,7 +292,7 @@ public function withQuery($query); * An empty fragment value is equivalent to removing the fragment. * * @param string $fragment The fragment to use with the new instance. - * @return self A new instance with the specified fragment. + * @return static A new instance with the specified fragment. */ public function withFragment($fragment); From 2a8e7649116916926433eea168857986b168491e Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Wed, 21 Oct 2015 00:21:56 +0300 Subject: [PATCH 03/16] UploadedFileInterface phpDoc typo fixed --- src/UploadedFileInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UploadedFileInterface.php b/src/UploadedFileInterface.php index 5ad288d..f8a6901 100644 --- a/src/UploadedFileInterface.php +++ b/src/UploadedFileInterface.php @@ -58,7 +58,7 @@ public function getStream(); * @see http://php.net/is_uploaded_file * @see http://php.net/move_uploaded_file * @param string $targetPath Path to which to move the uploaded file. - * @throws \InvalidArgumentException if the $path specified is invalid. + * @throws \InvalidArgumentException if the $targetPath specified is invalid. * @throws \RuntimeException on any error during the move operation, or on * the second or subsequent call to the method. */ From 47cd67d7dba706652aa41a06089b1bf1c0bc40a3 Mon Sep 17 00:00:00 2001 From: mouhamed Date: Mon, 14 Dec 2015 16:39:29 +0100 Subject: [PATCH 04/16] Fix typo in RequestInterface.php --- src/RequestInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RequestInterface.php b/src/RequestInterface.php index 75c802e..2b45130 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -107,7 +107,7 @@ public function getUri(); * setting `$preserveHost` to `true`. When `$preserveHost` is set to * `true`, this method interacts with the Host header in the following ways: * - * - If the the Host header is missing or empty, and the new URI contains + * - If the Host header is missing or empty, and the new URI contains * a host component, this method MUST update the Host header in the returned * request. * - If the Host header is missing or empty, and the new URI does not contain a From c2290af463fd85cceead19b21e35d46a15744f71 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Wed, 6 Jan 2016 10:31:37 -0600 Subject: [PATCH 05/16] Add homepage. Including the homepage link makes package mirrors and directories such as those generated by Satis nicer to read and more useful (providing a direct link to the project page). --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 4774b61..b0d2937 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "psr/http-message", "description": "Common interface for HTTP messages", "keywords": ["psr", "psr-7", "http", "http-message", "request", "response"], + "homepage": "https://github.com/php-fig/http-message", "license": "MIT", "authors": [ { From 1534e52263073006dc46c605c813842cec719ac7 Mon Sep 17 00:00:00 2001 From: Damon Date: Mon, 7 Mar 2016 19:40:31 +0200 Subject: [PATCH 06/16] Update RequestInterface.php Correcting inaccurate documentation --- src/RequestInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RequestInterface.php b/src/RequestInterface.php index 75c802e..76d6341 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -53,7 +53,7 @@ public function getRequestTarget(); * immutability of the message, and MUST return an instance that has the * changed request target. * - * @link http://tools.ietf.org/html/rfc7230#section-2.7 (for the various + * @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various * request-target forms allowed in request messages) * @param mixed $requestTarget * @return self From d0aabc038f1f3ff665dfe1e9673bcd0df609c681 Mon Sep 17 00:00:00 2001 From: MichaelC Date: Wed, 3 Aug 2016 20:47:37 +0100 Subject: [PATCH 07/16] Fix docblock to specify that it should be an array of nested strings, not just array --- src/MessageInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MessageInterface.php b/src/MessageInterface.php index 8f67a05..1bf5a0b 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -61,7 +61,7 @@ public function withProtocolVersion($version); * While header names are not case-sensitive, getHeaders() will preserve the * exact case in which headers were originally specified. * - * @return array Returns an associative array of the message's headers. Each + * @return string[][] Returns an associative array of the message's headers. Each * key MUST be a header name, and each value MUST be an array of strings * for that header. */ From f6561bf28d520154e4b0ec72be95418abe6d9363 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Sat, 6 Aug 2016 09:39:51 -0500 Subject: [PATCH 08/16] Added CHANGELOG for 1.0.1 --- CHANGELOG.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..74b1ef9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,36 @@ +# Changelog + +All notable changes to this project will be documented in this file, in reverse chronological order by release. + +## 1.0.1 - 2016-08-06 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Updated all `@return self` annotation references in interfaces to use + `@return static`, which more closelly follows the semantics of the + specification. +- Updated the `MessageInterface::getHeaders()` return annotation to use the + value `string[][]`, indicating the format is a nested array of strings. +- Updated the `@link` annotation for `RequestInterface::withRequestTarget()` + to point to the correct section of RFC 7230. +- Updated the `ServerRequestInterface::withUploadedFiles()` parameter annotation + to add the parameter name (`$uploadedFiles`). +- Updated a `@throws` annotation for the `UploadedFileInterface::moveTo()` + method to correctly reference the method parameter (it was referencing an + incorrect parameter name previously). + +## 1.0.0 - 2016-05-18 + +Initial stable release; reflects accepted PSR-7 specification. From efd67d1dc14a7ef4fc4e518e7dee91c271d524e4 Mon Sep 17 00:00:00 2001 From: Gabi DJ Date: Thu, 29 Aug 2019 16:16:46 +0300 Subject: [PATCH 09/16] Added PSR-7 Interfaces brief explanations and Basic Usage Guide (#79) * Added PSR-7 Interfaces Usage guide using Zend Diactoros * Corrected errors in documentation corrected PSR-7 methods explanations corrected typos removed concrete usage of diactoros removed unnecessary text removed zend-diactoros autoload added assumption of $request and $response * Update PSR7-Usage.md * Corrected interfaces list --- README.md | 5 +- docs/PSR7-Interfaces.md | 130 ++++++++++++++++++++++++++++++++ docs/PSR7-Usage.md | 159 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 docs/PSR7-Interfaces.md create mode 100644 docs/PSR7-Usage.md diff --git a/README.md b/README.md index 2818533..2668be6 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,7 @@ interface that describes a HTTP message. See the specification for more details. Usage ----- -We'll certainly need some stuff in here. \ No newline at end of file +Before reading the usage guide we recommend reading the PSR-7 interfaces method list: + +* [`PSR-7 Interfaces Method List`](docs/PSR7-Interfaces.md) +* [`PSR-7 Usage Guide`](docs/PSR7-Usage.md) \ No newline at end of file diff --git a/docs/PSR7-Interfaces.md b/docs/PSR7-Interfaces.md new file mode 100644 index 0000000..3a7e7dd --- /dev/null +++ b/docs/PSR7-Interfaces.md @@ -0,0 +1,130 @@ +# Interfaces + +The purpose of this list is to help in finding the methods when working with PSR-7. This can be considered as a cheatsheet for PSR-7 interfaces. + +The interfaces defined in PSR-7 are the following: + +| Class Name | Description | +|---|---| +| [Psr\Http\Message\MessageInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagemessageinterface) | Representation of a HTTP message | +| [Psr\Http\Message\RequestInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagerequestinterface) | Representation of an outgoing, client-side request. | +| [Psr\Http\Message\ServerRequestInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageserverrequestinterface) | Representation of an incoming, server-side HTTP request. | +| [Psr\Http\Message\ResponseInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageresponseinterface) | Representation of an outgoing, server-side response. | +| [Psr\Http\Message\StreamInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagestreaminterface) | Describes a data stream | +| [Psr\Http\Message\UriInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageuriinterface) | Value object representing a URI. | +| [Psr\Http\Message\UploadedFileInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageuploadedfileinterface) | Value object representing a file uploaded through an HTTP request. | + +## `Psr\Http\Message\MessageInterface` Methods + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `getProtocolVersion()` | Retrieve HTTP protocol version | 1.0 or 1.1 | +| `withProtocolVersion($version)` | Returns new message instance with given HTTP protocol version | | +| `getHeaders()` | Retrieve all HTTP Headers | [Request Header List](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields), [Response Header List](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Response_fields) | +| `hasHeader($name)` | Checks if HTTP Header with given name exists | | +| `getHeader($name)` | Retrieves a array with the values for a single header | | +| `getHeaderLine($name)` | Retrieves a comma-separated string of the values for a single header | | +| `withHeader($name, $value)` | Returns new message instance with given HTTP Header | if the header existed in the original instance, replaces the header value from the original message with the value provided when creating the new instance. | +| `withAddedHeader($name, $value)` | Returns new message instance with appended value to given header | If header already exists value will be appended, if not a new header will be created | +| `withoutHeader($name)` | Removes HTTP Header with given name| | +| `getBody()` | Retrieves the HTTP Message Body | Returns object implementing `StreamInterface`| +| `withBody(StreamInterface $body)` | Returns new message instance with given HTTP Message Body | | + + +## `Psr\Http\Message\RequestInterface` Methods + +Same methods as `Psr\Http\Message\MessageInterface` + the following methods: + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `getRequestTarget()` | Retrieves the message's request target | origin-form, absolute-form, authority-form, asterisk-form ([RFC7230](https://www.rfc-editor.org/rfc/rfc7230.txt)) | +| `withRequestTarget($requestTarget)` | Return a new message instance with the specific request-target | | +| `getMethod()` | Retrieves the HTTP method of the request. | GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE (defined in [RFC7231](https://tools.ietf.org/html/rfc7231)), PATCH (defined in [RFC5789](https://tools.ietf.org/html/rfc5789)) | +| `withMethod($method)` | Returns a new message instance with the provided HTTP method | | +| `getUri()` | Retrieves the URI instance | | +| `withUri(UriInterface $uri, $preserveHost = false)` | Returns a new message instance with the provided URI | | + + +## `Psr\Http\Message\ServerRequestInterface` Methods + +Same methods as `Psr\Http\Message\RequestInterface` + the following methods: + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `getServerParams() ` | Retrieve server parameters | Typically derived from `$_SERVER` | +| `getCookieParams()` | Retrieves cookies sent by the client to the server. | Typically derived from `$_COOKIES` | +| `withCookieParams(array $cookies)` | Returns a new request instance with the specified cookies | | +| `withQueryParams(array $query)` | Returns a new request instance with the specified query string arguments | | +| `getUploadedFiles()` | Retrieve normalized file upload data | | +| `withUploadedFiles(array $uploadedFiles)` | Returns a new request instance with the specified uploaded files | | +| `getParsedBody()` | Retrieve any parameters provided in the request body | | +| `withParsedBody($data)` | Returns a new request instance with the specified body parameters | | +| `getAttributes()` | Retrieve attributes derived from the request | | +| `getAttribute($name, $default = null)` | Retrieve a single derived request attribute | | +| `withAttribute($name, $value)` | Returns a new request instance with the specified derived request attribute | | +| `withoutAttribute($name)` | Returns a new request instance that without the specified derived request attribute | | + +## `Psr\Http\Message\ResponseInterface` Methods: + +Same methods as `Psr\Http\Message\MessageInterface` + the following methods: + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `getStatusCode()` | Gets the response status code. | | +| `withStatus($code, $reasonPhrase = '')` | Returns a new response instance with the specified status code and, optionally, reason phrase. | | +| `getReasonPhrase()` | Gets the response reason phrase associated with the status code. | | + +## `Psr\Http\Message\StreamInterface` Methods + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `__toString()` | Reads all data from the stream into a string, from the beginning to end. | | +| `close()` | Closes the stream and any underlying resources. | | +| `detach()` | Separates any underlying resources from the stream. | | +| `getSize()` | Get the size of the stream if known. | | +| `eof()` | Returns true if the stream is at the end of the stream.| | +| `isSeekable()` | Returns whether or not the stream is seekable. | | +| `seek($offset, $whence = SEEK_SET)` | Seek to a position in the stream. | | +| `rewind()` | Seek to the beginning of the stream. | | +| `isWritable()` | Returns whether or not the stream is writable. | | +| `write($string)` | Write data to the stream. | | +| `isReadable()` | Returns whether or not the stream is readable. | | +| `read($length)` | Read data from the stream. | | +| `getContents()` | Returns the remaining contents in a string | | +| `getMetadata($key = null)()` | Get stream metadata as an associative array or retrieve a specific key. | | + +## `Psr\Http\Message\UriInterface` Methods + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `getScheme()` | Retrieve the scheme component of the URI. | | +| `getAuthority()` | Retrieve the authority component of the URI. | | +| `getUserInfo()` | Retrieve the user information component of the URI. | | +| `getHost()` | Retrieve the host component of the URI. | | +| `getPort()` | Retrieve the port component of the URI. | | +| `getPath()` | Retrieve the path component of the URI. | | +| `getQuery()` | Retrieve the query string of the URI. | | +| `getFragment()` | Retrieve the fragment component of the URI. | | +| `withScheme($scheme)` | Return an instance with the specified scheme. | | +| `withUserInfo($user, $password = null)` | Return an instance with the specified user information. | | +| `withHost($host)` | Return an instance with the specified host. | | +| `withPort($port)` | Return an instance with the specified port. | | +| `withPath($path)` | Return an instance with the specified path. | | +| `withQuery($query)` | Return an instance with the specified query string. | | +| `withFragment($fragment)` | Return an instance with the specified URI fragment. | | +| `__toString()` | Return the string representation as a URI reference. | | + +## `Psr\Http\Message\UploadedFileInterface` Methods + +| Method Name | Description | Notes | +|------------------------------------| ----------- | ----- | +| `getStream()` | Retrieve a stream representing the uploaded file. | | +| `moveTo($targetPath)` | Move the uploaded file to a new location. | | +| `getSize()` | Retrieve the file size. | | +| `getError()` | Retrieve the error associated with the uploaded file. | | +| `getClientFilename()` | Retrieve the filename sent by the client. | | +| `getClientMediaType()` | Retrieve the media type sent by the client. | | + +> `RequestInterface`, `ServerRequestInterface`, `ResponseInterface` extend `MessageInterface` because the `Request` and the `Response` are `HTTP Messages`. +> When using `ServerRequestInterface`, both `RequestInterface` and `Psr\Http\Message\MessageInterface` methods are considered. + diff --git a/docs/PSR7-Usage.md b/docs/PSR7-Usage.md new file mode 100644 index 0000000..b6d048a --- /dev/null +++ b/docs/PSR7-Usage.md @@ -0,0 +1,159 @@ +### PSR-7 Usage + +All PSR-7 applications comply with these interfaces +They were created to establish a standard between middleware implementations. + +> `RequestInterface`, `ServerRequestInterface`, `ResponseInterface` extend `MessageInterface` because the `Request` and the `Response` are `HTTP Messages`. +> When using `ServerRequestInterface`, both `RequestInterface` and `Psr\Http\Message\MessageInterface` methods are considered. + + +The following examples will illustrate how basic operations are done in PSR-7. + +##### Examples + + +For this examples to work (at least) a PSR-7 implementation package is required. (eg: zendframework/zend-diactoros, guzzlehttp/psr7, slim/slim, etc) +All PSR-7 implementations should have the same behaviour. + +The following will be assumed: +`$request` is an object of `Psr\Http\Message\RequestInterface` and + +`$response` is an object implementing `Psr\Http\Message\RequestInterface` + + +### Working with HTTP Headers + +#### Adding headers to response: + +```php +$response->withHeader('My-Custom-Header', 'My Custom Message'); +``` + +#### Appending values to headers + +```php +$response->withAddedHeader('My-Custom-Header', 'The second message'); +``` + +#### Checking if header exists: + +```php +$request->hasHeader('My-Custom-Header'); // will return false +$response->hasHeader('My-Custom-Header'); // will return true +``` + +> Note: My-Custom-Header was only added in the Response + +#### Getting comma-separated values from a header (also applies to request) + +```php +// getting value from request headers +$request->getHeaderLine('Content-Type'); // will return: "text/html; charset=UTF-8" +// getting value from response headers +$response->getHeaderLine('My-Custom-Header'); // will return: "My Custom Message; The second message" +``` + +#### Getting array of value from a header (also applies to request) +```php +// getting value from request headers +$request->getHeader('Content-Type'); // will return: ["text/html", "charset=UTF-8"] +// getting value from response headers +$response->getHeader('My-Custom-Header'); // will return: ["My Custom Message", "The second message"] +``` + +#### Removing headers from HTTP Messages +```php +// removing a header from Request, removing deprecated "Content-MD5" header +$request->withoutHeader('Content-MD5'); + +// removing a header from Response +// effect: the browser won't know the size of the stream +// the browser will download the stream till it ends +$response->withoutHeader('Content-Length'); +``` + +### Working with HTTP Message Body + +When working with the PSR-7 there are two methods of implementation: +#### 1. Getting the body separately + +> This method makes the body handling easier to understand and is useful when repeatedly calling body methods. (You only call `getBody()` once). Using this method mistakes like `$response->write()` are also prevented. + +```php +$body = $response->getBody(); +// operations on body, eg. read, write, seek +// ... +// replacing the old body +$response->withBody($body); +// this last statement is optional as we working with objects +// in this case the "new" body is same with the "old" one +// the $body variable has the same value as the one in $request, only the reference is passed +``` + +#### 2. Working directly on response + +> This method is useful when only performing few operations as the `$request->getBody()` statement fragment is required + +```php +$response->getBody()->write('hello'); +``` + +### Getting the body contents + +The following snippet gets the contents of a stream contents. +> Note: Streams must be rewinded, if content was written into streams, it will be ignored when calling `getContents()` because the stream pointer is set to the last character, which is `\0` - meaning end of stream. +```php +$body = $response->getBody(); +$body->rewind(); // or $body->seek(0); +$bodyText = $body->getContents(); +``` +> Note: If `$body->seek(1)` is called before `$body->getContents()`, the first character will be ommited as the starting pointer is set to `1`, not `0`. This is why using `$body->rewind()` is recommended. + +### Append to body + +```php +$response->getBody()->write('Hello'); // writing directly +$body = $request->getBody(); // which is a `StreamInterface` +$body->write('xxxxx'); +``` + +### Prepend to body +Prepending is different when it comes to streams. The content must be copied before writing the content to be prepended. +The following example will explain the behaviour of streams. + +```php +// assuming our response is initially empty +$body = $repsonse->getBody(); +// writing the string "abcd" +$body->write('abcd'); + +// seeking to start of stream +$body->seek(0); +// writing 'ef' +$body->write('ef'); // at this point the stream contains "efcd" +``` + +#### Prepending by rewriting separately + +```php +// assuming our response body stream only contains: "abcd" +$body = $response->getBody(); +$body->rewind(); +$contents = $body->getContents(); // abcd +// seeking the stream to beginning +$body->rewind(); +$body->write('ef'); // stream contains "efcd" +$body->write($contents); // stream contains "efabcd" +``` + +> Note: `getContents()` seeks the stream while reading it, therefore if the second `rewind()` method call was not present the stream would have resulted in `abcdefabcd` because the `write()` method appends to stream if not preceeded by `rewind()` or `seek(0)`. + +#### Prepending by using contents as a string +```php +$body = $response->getBody(); +$body->rewind(); +$contents = $body->getContents(); // efabcd +$contents = 'ef'.$contents; +$body->rewind(); +$body->write($contents); +``` From 5cd5ad79255dfa7243fdbc704c6f6b7374f1c07a Mon Sep 17 00:00:00 2001 From: Stilch Date: Sun, 9 May 2021 12:36:19 +0500 Subject: [PATCH 10/16] Adds parameter typehints --- composer.json | 4 ++-- src/MessageInterface.php | 16 +++++++++------- src/RequestInterface.php | 6 ++++-- src/ResponseInterface.php | 4 +++- src/ServerRequestInterface.php | 8 +++++--- src/StreamInterface.php | 12 +++++++----- src/UploadedFileInterface.php | 4 +++- src/UriInterface.php | 17 ++++++++++------- 8 files changed, 43 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index b0d2937..2dcd78b 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.3.0" + "php": ">=7.2.0" }, "autoload": { "psr-4": { @@ -20,7 +20,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } } } diff --git a/src/MessageInterface.php b/src/MessageInterface.php index dd46e5e..8cdb4ed 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -1,5 +1,7 @@ Date: Sun, 9 May 2021 12:51:39 +0500 Subject: [PATCH 11/16] Add return typehints --- composer.json | 2 +- src/MessageInterface.php | 22 +++++++++++----------- src/RequestInterface.php | 12 ++++++------ src/ResponseInterface.php | 6 +++--- src/ServerRequestInterface.php | 22 +++++++++++----------- src/StreamInterface.php | 18 +++++++++--------- src/UploadedFileInterface.php | 10 +++++----- src/UriInterface.php | 30 +++++++++++++++--------------- 8 files changed, 61 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index 2dcd78b..10ce369 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/src/MessageInterface.php b/src/MessageInterface.php index 8cdb4ed..fb15f78 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -25,7 +25,7 @@ interface MessageInterface * * @return string HTTP protocol version. */ - public function getProtocolVersion(); + public function getProtocolVersion(): string; /** * Return an instance with the specified HTTP protocol version. @@ -40,7 +40,7 @@ public function getProtocolVersion(); * @param string $version HTTP protocol version * @return static */ - public function withProtocolVersion(string $version); + public function withProtocolVersion(string $version): MessageInterface; /** * Retrieves all message header values. @@ -67,7 +67,7 @@ public function withProtocolVersion(string $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. @@ -77,7 +77,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(string $name); + public function hasHeader(string $name): bool; /** * Retrieves a message header value by the given case-insensitive name. @@ -93,7 +93,7 @@ public function hasHeader(string $name); * header. If the header does not appear in the message, this method MUST * return an empty array. */ - public function getHeader(string $name); + public function getHeader(string $name): array; /** * Retrieves a comma-separated string of the values for a single header. @@ -114,7 +114,7 @@ public function getHeader(string $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(string $name); + public function getHeaderLine(string $name): string; /** * Return an instance with the provided value replacing the specified header. @@ -131,7 +131,7 @@ public function getHeaderLine(string $name); * @return static * @throws \InvalidArgumentException for invalid header names or values. */ - public function withHeader(string $name, $value); + public function withHeader(string $name, $value): MessageInterface; /** * Return an instance with the specified header appended with the given value. @@ -149,7 +149,7 @@ public function withHeader(string $name, $value); * @return static * @throws \InvalidArgumentException for invalid header names or values. */ - public function withAddedHeader(string $name, $value); + public function withAddedHeader(string $name, $value): MessageInterface; /** * Return an instance without the specified header. @@ -163,14 +163,14 @@ public function withAddedHeader(string $name, $value); * @param string $name Case-insensitive header field name to remove. * @return static */ - public function withoutHeader(string $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. @@ -185,5 +185,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; } diff --git a/src/RequestInterface.php b/src/RequestInterface.php index b96c022..165b76b 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -41,7 +41,7 @@ interface RequestInterface extends MessageInterface * * @return string */ - public function getRequestTarget(); + public function getRequestTarget(): string; /** * Return an instance with the specific request-target. @@ -60,14 +60,14 @@ public function getRequestTarget(); * @param mixed $requestTarget * @return static */ - public function withRequestTarget($requestTarget); + public function withRequestTarget($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. @@ -84,7 +84,7 @@ public function getMethod(); * @return static * @throws \InvalidArgumentException for invalid HTTP methods. */ - public function withMethod(string $method); + public function withMethod(string $method): RequestInterface; /** * Retrieves the URI instance. @@ -95,7 +95,7 @@ public function withMethod(string $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. @@ -127,5 +127,5 @@ public function getUri(); * @param bool $preserveHost Preserve the original state of the Host header. * @return static */ - public function withUri(UriInterface $uri, bool $preserveHost = false); + public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface; } diff --git a/src/ResponseInterface.php b/src/ResponseInterface.php index f85ca48..b2aa937 100644 --- a/src/ResponseInterface.php +++ b/src/ResponseInterface.php @@ -29,7 +29,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. @@ -51,7 +51,7 @@ public function getStatusCode(); * @return static * @throws \InvalidArgumentException For invalid status code arguments. */ - public function withStatus(int $code, string $reasonPhrase = ''); + public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface; /** * Gets the response reason phrase associated with the status code. @@ -66,5 +66,5 @@ public function withStatus(int $code, string $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; } diff --git a/src/ServerRequestInterface.php b/src/ServerRequestInterface.php index 5e6d964..a5aff59 100644 --- a/src/ServerRequestInterface.php +++ b/src/ServerRequestInterface.php @@ -53,7 +53,7 @@ interface ServerRequestInterface extends RequestInterface * * @return array */ - public function getServerParams(); + public function getServerParams(): array; /** * Retrieve cookies. @@ -65,7 +65,7 @@ public function getServerParams(); * * @return array */ - public function getCookieParams(); + public function getCookieParams(): array; /** * Return an instance with the specified cookies. @@ -84,7 +84,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. @@ -98,7 +98,7 @@ public function withCookieParams(array $cookies); * * @return array */ - public function getQueryParams(); + public function getQueryParams(): array; /** * Return an instance with the specified query string arguments. @@ -122,7 +122,7 @@ public function getQueryParams(); * $_GET. * @return static */ - public function withQueryParams(array $query); + public function withQueryParams(array $query): ServerRequestInterface; /** * Retrieve normalized file upload data. @@ -136,7 +136,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. @@ -149,7 +149,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. @@ -196,7 +196,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. @@ -209,7 +209,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. @@ -243,7 +243,7 @@ public function getAttribute(string $name, $default = null); * @param mixed $value The value of the attribute. * @return static */ - public function withAttribute(string $name, $value); + public function withAttribute(string $name, $value): ServerRequestInterface; /** * Return an instance that removes the specified derived request attribute. @@ -259,5 +259,5 @@ public function withAttribute(string $name, $value); * @param string $name The attribute name. * @return static */ - public function withoutAttribute(string $name); + public function withoutAttribute(string $name): ServerRequestInterface; } diff --git a/src/StreamInterface.php b/src/StreamInterface.php index 5924663..e6d2a50 100644 --- a/src/StreamInterface.php +++ b/src/StreamInterface.php @@ -50,7 +50,7 @@ public function detach(); * * @return int|null Returns the size in bytes if known, or null if unknown. */ - public function getSize(); + public function getSize(): ?int; /** * Returns the current position of the file read/write pointer @@ -58,21 +58,21 @@ public function getSize(); * @return int Position of the file pointer * @throws \RuntimeException on error. */ - public function tell(); + public function tell(): int; /** * Returns true if the stream is at the end of the stream. * * @return bool */ - public function eof(); + public function eof(): bool; /** * Returns whether or not the stream is seekable. * * @return bool */ - public function isSeekable(); + public function isSeekable(): bool; /** * Seek to a position in the stream. @@ -105,7 +105,7 @@ public function rewind(); * * @return bool */ - public function isWritable(); + public function isWritable(): bool; /** * Write data to the stream. @@ -114,14 +114,14 @@ public function isWritable(); * @return int Returns the number of bytes written to the stream. * @throws \RuntimeException on failure. */ - public function write(string $string); + public function write(string $string): int; /** * Returns whether or not the stream is readable. * * @return bool */ - public function isReadable(); + public function isReadable(): bool; /** * Read data from the stream. @@ -133,7 +133,7 @@ public function isReadable(); * if no bytes are available. * @throws \RuntimeException if an error occurs. */ - public function read(int $length); + public function read(int $length): string; /** * Returns the remaining contents in a string @@ -142,7 +142,7 @@ public function read(int $length); * @throws \RuntimeException if unable to read or an error occurs while * reading. */ - public function getContents(); + public function getContents(): string; /** * Get stream metadata as an associative array or retrieve a specific key. diff --git a/src/UploadedFileInterface.php b/src/UploadedFileInterface.php index aba6321..8b7b494 100644 --- a/src/UploadedFileInterface.php +++ b/src/UploadedFileInterface.php @@ -30,7 +30,7 @@ interface UploadedFileInterface * @throws \RuntimeException in cases when no stream is available or can be * created. */ - public function getStream(); + public function getStream(): StreamInterface; /** * Move the uploaded file to a new location. @@ -75,7 +75,7 @@ public function moveTo(string $targetPath); * * @return int|null The file size in bytes or null if unknown. */ - public function getSize(); + public function getSize(): ?int; /** * Retrieve the error associated with the uploaded file. @@ -91,7 +91,7 @@ public function getSize(); * @see http://php.net/manual/en/features.file-upload.errors.php * @return int One of PHP's UPLOAD_ERR_XXX constants. */ - public function getError(); + public function getError(): int; /** * Retrieve the filename sent by the client. @@ -106,7 +106,7 @@ public function getError(); * @return string|null The filename sent by the client or null if none * was provided. */ - public function getClientFilename(); + public function getClientFilename(): ?string; /** * Retrieve the media type sent by the client. @@ -121,5 +121,5 @@ public function getClientFilename(); * @return string|null The media type sent by the client or null if none * was provided. */ - public function getClientMediaType(); + public function getClientMediaType(): ?string; } diff --git a/src/UriInterface.php b/src/UriInterface.php index d974de0..1a321da 100644 --- a/src/UriInterface.php +++ b/src/UriInterface.php @@ -40,7 +40,7 @@ interface UriInterface * @see https://tools.ietf.org/html/rfc3986#section-3.1 * @return string The URI scheme. */ - public function getScheme(); + public function getScheme(): string; /** * Retrieve the authority component of the URI. @@ -60,7 +60,7 @@ public function getScheme(); * @see https://tools.ietf.org/html/rfc3986#section-3.2 * @return string The URI authority, in "[user-info@]host[:port]" format. */ - public function getAuthority(); + public function getAuthority(): string; /** * Retrieve the user information component of the URI. @@ -77,7 +77,7 @@ public function getAuthority(); * * @return string The URI user information, in "username[:password]" format. */ - public function getUserInfo(); + public function getUserInfo(): string; /** * Retrieve the host component of the URI. @@ -90,7 +90,7 @@ public function getUserInfo(); * @see http://tools.ietf.org/html/rfc3986#section-3.2.2 * @return string The URI host. */ - public function getHost(); + public function getHost(): string; /** * Retrieve the port component of the URI. @@ -107,7 +107,7 @@ public function getHost(); * * @return null|int The URI port. */ - public function getPort(); + public function getPort(): ?int; /** * Retrieve the path component of the URI. @@ -134,7 +134,7 @@ public function getPort(); * @see https://tools.ietf.org/html/rfc3986#section-3.3 * @return string The URI path. */ - public function getPath(); + public function getPath(): string; /** * Retrieve the query string of the URI. @@ -156,7 +156,7 @@ public function getPath(); * @see https://tools.ietf.org/html/rfc3986#section-3.4 * @return string The URI query string. */ - public function getQuery(); + public function getQuery(): string; /** * Retrieve the fragment component of the URI. @@ -174,7 +174,7 @@ public function getQuery(); * @see https://tools.ietf.org/html/rfc3986#section-3.5 * @return string The URI fragment. */ - public function getFragment(); + public function getFragment(): string; /** * Return an instance with the specified scheme. @@ -191,7 +191,7 @@ public function getFragment(); * @return static A new instance with the specified scheme. * @throws \InvalidArgumentException for invalid or unsupported schemes. */ - public function withScheme(string $scheme); + public function withScheme(string $scheme): UriInterface; /** * Return an instance with the specified user information. @@ -207,7 +207,7 @@ public function withScheme(string $scheme); * @param null|string $password The password associated with $user. * @return static A new instance with the specified user information. */ - public function withUserInfo(string $user, ?string $password = null); + public function withUserInfo(string $user, ?string $password = null): UriInterface; /** * Return an instance with the specified host. @@ -221,7 +221,7 @@ public function withUserInfo(string $user, ?string $password = null); * @return static A new instance with the specified host. * @throws \InvalidArgumentException for invalid hostnames. */ - public function withHost(string $host); + public function withHost(string $host): UriInterface; /** * Return an instance with the specified port. @@ -240,7 +240,7 @@ public function withHost(string $host); * @return static A new instance with the specified port. * @throws \InvalidArgumentException for invalid ports. */ - public function withPort(?int $port); + public function withPort(?int $port): UriInterface; /** * Return an instance with the specified path. @@ -264,7 +264,7 @@ public function withPort(?int $port); * @return static A new instance with the specified path. * @throws \InvalidArgumentException for invalid paths. */ - public function withPath(string $path); + public function withPath(string $path): UriInterface; /** * Return an instance with the specified query string. @@ -281,7 +281,7 @@ public function withPath(string $path); * @return static A new instance with the specified query string. * @throws \InvalidArgumentException for invalid query strings. */ - public function withQuery(string $query); + public function withQuery(string $query): UriInterface; /** * Return an instance with the specified URI fragment. @@ -297,7 +297,7 @@ public function withQuery(string $query); * @param string $fragment The fragment to use with the new instance. * @return static A new instance with the specified fragment. */ - public function withFragment(string $fragment); + public function withFragment(string $fragment): UriInterface; /** * Return the string representation as a URI reference. From 641e9f812d34d66373fa45ce7a1edf7e123d969a Mon Sep 17 00:00:00 2001 From: Stilch Date: Wed, 23 Feb 2022 17:40:53 +0500 Subject: [PATCH 12/16] Changed the requirements for the PHP version and removed declare strict types --- composer.json | 4 ++-- src/MessageInterface.php | 2 -- src/RequestInterface.php | 2 -- src/ResponseInterface.php | 2 -- src/ServerRequestInterface.php | 2 -- src/StreamInterface.php | 2 -- src/UploadedFileInterface.php | 2 -- src/UriInterface.php | 2 -- 8 files changed, 2 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 10ce369..a11e22b 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,11 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "require": { - "php": ">=7.2.0" + "php": "^7.2.0 || ^8.0.0" }, "autoload": { "psr-4": { diff --git a/src/MessageInterface.php b/src/MessageInterface.php index fb15f78..a83c985 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -1,7 +1,5 @@ Date: Sat, 25 Feb 2023 11:58:31 +0500 Subject: [PATCH 13/16] Changed php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2dcd78b..56e8c0a 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=7.2.0" + "php": "^7.2 || ^8.0" }, "autoload": { "psr-4": { From 6ae06cd6c84144d35be2f5a190cf9f8bc3e5db84 Mon Sep 17 00:00:00 2001 From: Aleksandr Golouz Date: Sat, 25 Feb 2023 11:58:42 +0500 Subject: [PATCH 14/16] Added a string typehint for the $requestTarget argument --- src/RequestInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RequestInterface.php b/src/RequestInterface.php index b96c022..38066df 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -57,10 +57,10 @@ 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); /** * Retrieves the HTTP method of the request. From 520dd0e3af2062e41e9e712893c2121d893318b0 Mon Sep 17 00:00:00 2001 From: Aleksandr Golouz Date: Sat, 25 Feb 2023 12:11:24 +0500 Subject: [PATCH 15/16] Added string as return types for __toString --- src/StreamInterface.php | 2 +- src/UriInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StreamInterface.php b/src/StreamInterface.php index 46a9a48..7f068f8 100644 --- a/src/StreamInterface.php +++ b/src/StreamInterface.php @@ -25,7 +25,7 @@ interface StreamInterface * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring * @return string */ - public function __toString(); + public function __toString(): string; /** * Closes the stream and any underlying resources. diff --git a/src/UriInterface.php b/src/UriInterface.php index 4b5f4f2..15e2cf2 100644 --- a/src/UriInterface.php +++ b/src/UriInterface.php @@ -320,5 +320,5 @@ public function withFragment(string $fragment): UriInterface; * @see http://tools.ietf.org/html/rfc3986#section-4.1 * @return string */ - public function __toString(); + public function __toString(): string; } From 3def5216f7e2ef8e402b1f44746a61fe68b3e303 Mon Sep 17 00:00:00 2001 From: Aleksandr Golouz Date: Sat, 25 Feb 2023 12:11:38 +0500 Subject: [PATCH 16/16] Added void as return types --- src/RequestInterface.php | 4 ++-- src/StreamInterface.php | 6 +++--- src/UploadedFileInterface.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RequestInterface.php b/src/RequestInterface.php index 5c60cbe..0839a26 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -55,10 +55,10 @@ public function getRequestTarget(): string; * * @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): RequestInterface; + public function withRequestTarget(string $requestTarget): RequestInterface; /** * Retrieves the HTTP method of the request. diff --git a/src/StreamInterface.php b/src/StreamInterface.php index 7f068f8..a62aabb 100644 --- a/src/StreamInterface.php +++ b/src/StreamInterface.php @@ -32,7 +32,7 @@ public function __toString(): string; * * @return void */ - public function close(); + public function close(): void; /** * Separates any underlying resources from the stream. @@ -84,7 +84,7 @@ public function isSeekable(): bool; * SEEK_END: Set position to end-of-stream plus offset. * @throws \RuntimeException on failure. */ - public function seek(int $offset, int $whence = SEEK_SET); + public function seek(int $offset, int $whence = SEEK_SET): void; /** * Seek to the beginning of the stream. @@ -96,7 +96,7 @@ public function seek(int $offset, int $whence = SEEK_SET); * @link http://www.php.net/manual/en/function.fseek.php * @throws \RuntimeException on failure. */ - public function rewind(); + public function rewind(): void; /** * Returns whether or not the stream is writable. diff --git a/src/UploadedFileInterface.php b/src/UploadedFileInterface.php index 3cb8f42..dd19d65 100644 --- a/src/UploadedFileInterface.php +++ b/src/UploadedFileInterface.php @@ -62,7 +62,7 @@ public function getStream(): StreamInterface; * @throws \RuntimeException on any error during the move operation, or on * the second or subsequent call to the method. */ - public function moveTo(string $targetPath); + public function moveTo(string $targetPath): void; /** * Retrieve the file size.