From 4ee25b992944628e854abdb38b4a1ca5a43f213d Mon Sep 17 00:00:00 2001 From: Maurits van der Schee Date: Sun, 8 Sep 2024 19:37:48 +0200 Subject: [PATCH] update dependencies --- api.include.php | 165 +++++++++++++++++++++++++----------------------- api.php | 165 +++++++++++++++++++++++++----------------------- composer.lock | 18 +++--- 3 files changed, 183 insertions(+), 165 deletions(-) diff --git a/api.include.php b/api.include.php index c30b0f7b..2029db14 100644 --- a/api.include.php +++ b/api.include.php @@ -136,10 +136,10 @@ interface UploadedFileFactoryInterface * * @param StreamInterface $stream Underlying stream representing the * uploaded file content. - * @param int $size in bytes + * @param int|null $size in bytes * @param int $error PHP file upload error - * @param string $clientFilename Filename as provided by the client, if any. - * @param string $clientMediaType Media type as provided by the client, if any. + * @param string|null $clientFilename Filename as provided by the client, if any. + * @param string|null $clientMediaType Media type as provided by the client, if any. * * @return UploadedFileInterface * @@ -147,10 +147,10 @@ interface UploadedFileFactoryInterface */ public function createUploadedFile( StreamInterface $stream, - int $size = null, + ?int $size = null, int $error = \UPLOAD_ERR_OK, - string $clientFilename = null, - string $clientMediaType = null + ?string $clientFilename = null, + ?string $clientMediaType = null ): UploadedFileInterface; } } @@ -197,7 +197,7 @@ interface MessageInterface * * @return string HTTP protocol version. */ - public function getProtocolVersion(); + public function getProtocolVersion(): string; /** * Return an instance with the specified HTTP protocol version. @@ -212,7 +212,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. @@ -239,7 +239,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. @@ -249,7 +249,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. @@ -265,7 +265,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. @@ -286,7 +286,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. @@ -303,7 +303,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. @@ -321,7 +321,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. @@ -335,14 +335,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. @@ -357,7 +357,7 @@ public function getBody(); * @return static * @throws \InvalidArgumentException When the body is not valid. */ - public function withBody(StreamInterface $body); + public function withBody(StreamInterface $body): MessageInterface; } } @@ -401,7 +401,7 @@ interface RequestInterface extends MessageInterface * * @return string */ - public function getRequestTarget(); + public function getRequestTarget(): string; /** * Return an instance with the specific request-target. @@ -420,14 +420,14 @@ public function getRequestTarget(); * @param string $requestTarget * @return static */ - public function withRequestTarget(string $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. @@ -444,7 +444,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. @@ -455,7 +455,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. @@ -487,7 +487,7 @@ 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; } } @@ -519,7 +519,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. @@ -541,7 +541,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. @@ -556,7 +556,7 @@ 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; } } @@ -612,7 +612,7 @@ interface ServerRequestInterface extends RequestInterface * * @return array */ - public function getServerParams(); + public function getServerParams(): array; /** * Retrieve cookies. @@ -624,7 +624,7 @@ public function getServerParams(); * * @return array */ - public function getCookieParams(); + public function getCookieParams(): array; /** * Return an instance with the specified cookies. @@ -643,7 +643,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. @@ -657,7 +657,7 @@ public function withCookieParams(array $cookies); * * @return array */ - public function getQueryParams(); + public function getQueryParams(): array; /** * Return an instance with the specified query string arguments. @@ -681,7 +681,7 @@ public function getQueryParams(); * $_GET. * @return static */ - public function withQueryParams(array $query); + public function withQueryParams(array $query): ServerRequestInterface; /** * Retrieve normalized file upload data. @@ -695,7 +695,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. @@ -708,7 +708,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. @@ -755,7 +755,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. @@ -768,7 +768,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. @@ -802,7 +802,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. @@ -818,7 +818,7 @@ 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; } } @@ -848,14 +848,14 @@ 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. * * @return void */ - public function close(); + public function close(): void; /** * Separates any underlying resources from the stream. @@ -871,7 +871,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 @@ -879,21 +879,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. @@ -907,7 +907,7 @@ public function isSeekable(); * 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. @@ -919,14 +919,14 @@ 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. * * @return bool */ - public function isWritable(); + public function isWritable(): bool; /** * Write data to the stream. @@ -935,14 +935,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. @@ -954,7 +954,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 @@ -963,7 +963,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. @@ -1010,7 +1010,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. @@ -1044,7 +1044,7 @@ public function getStream(); * @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. @@ -1055,7 +1055,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. @@ -1071,7 +1071,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. @@ -1086,7 +1086,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. @@ -1101,7 +1101,7 @@ 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; } } @@ -1144,7 +1144,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. @@ -1164,7 +1164,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. @@ -1181,7 +1181,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. @@ -1194,7 +1194,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. @@ -1211,7 +1211,7 @@ public function getHost(); * * @return null|int The URI port. */ - public function getPort(); + public function getPort(): ?int; /** * Retrieve the path component of the URI. @@ -1238,7 +1238,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. @@ -1260,7 +1260,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. @@ -1278,7 +1278,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. @@ -1295,7 +1295,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. @@ -1311,7 +1311,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. @@ -1325,7 +1325,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. @@ -1344,7 +1344,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. @@ -1368,7 +1368,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. @@ -1385,7 +1385,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. @@ -1401,7 +1401,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. @@ -1426,7 +1426,7 @@ public function withFragment(string $fragment); * @see http://tools.ietf.org/html/rfc3986#section-4.1 * @return string */ - public function __toString(); + public function __toString(): string; } } @@ -2513,11 +2513,19 @@ public function getContents(): string throw new \RuntimeException('Stream is detached'); } - if (false === $contents = @\stream_get_contents($this->stream)) { - throw new \RuntimeException('Unable to read stream contents: ' . (\error_get_last()['message'] ?? '')); - } + $exception = null; + + \set_error_handler(static function ($type, $message) use (&$exception) { + throw $exception = new \RuntimeException('Unable to read stream contents: ' . $message); + }); - return $contents; + try { + return \stream_get_contents($this->stream); + } catch (\Throwable $e) { + throw $e === $exception ? $e : new \RuntimeException('Unable to read stream contents: ' . $e->getMessage(), 0, $e); + } finally { + \restore_error_handler(); + } } /** @@ -3306,7 +3314,7 @@ public function fromGlobals(): ServerRequestInterface /** * {@inheritdoc} */ - public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], /*?array*/ $post = null, array $files = [], $body = null): ServerRequestInterface + public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], ?array $post = null, array $files = [], $body = null): ServerRequestInterface { $method = $this->getMethodFromEnv($server); $uri = $this->getUriFromEnvWithHTTP($server); @@ -3575,7 +3583,8 @@ public function fromArrays( array $server, array $headers = [], array $cookie = [], - array $get = [], /*?array*/ $post = null, + array $get = [], + ?array $post = null, array $files = [], $body = null ): ServerRequestInterface; diff --git a/api.php b/api.php index f6cfabfa..cc6ea906 100644 --- a/api.php +++ b/api.php @@ -136,10 +136,10 @@ interface UploadedFileFactoryInterface * * @param StreamInterface $stream Underlying stream representing the * uploaded file content. - * @param int $size in bytes + * @param int|null $size in bytes * @param int $error PHP file upload error - * @param string $clientFilename Filename as provided by the client, if any. - * @param string $clientMediaType Media type as provided by the client, if any. + * @param string|null $clientFilename Filename as provided by the client, if any. + * @param string|null $clientMediaType Media type as provided by the client, if any. * * @return UploadedFileInterface * @@ -147,10 +147,10 @@ interface UploadedFileFactoryInterface */ public function createUploadedFile( StreamInterface $stream, - int $size = null, + ?int $size = null, int $error = \UPLOAD_ERR_OK, - string $clientFilename = null, - string $clientMediaType = null + ?string $clientFilename = null, + ?string $clientMediaType = null ): UploadedFileInterface; } } @@ -197,7 +197,7 @@ interface MessageInterface * * @return string HTTP protocol version. */ - public function getProtocolVersion(); + public function getProtocolVersion(): string; /** * Return an instance with the specified HTTP protocol version. @@ -212,7 +212,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. @@ -239,7 +239,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. @@ -249,7 +249,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. @@ -265,7 +265,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. @@ -286,7 +286,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. @@ -303,7 +303,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. @@ -321,7 +321,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. @@ -335,14 +335,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. @@ -357,7 +357,7 @@ public function getBody(); * @return static * @throws \InvalidArgumentException When the body is not valid. */ - public function withBody(StreamInterface $body); + public function withBody(StreamInterface $body): MessageInterface; } } @@ -401,7 +401,7 @@ interface RequestInterface extends MessageInterface * * @return string */ - public function getRequestTarget(); + public function getRequestTarget(): string; /** * Return an instance with the specific request-target. @@ -420,14 +420,14 @@ public function getRequestTarget(); * @param string $requestTarget * @return static */ - public function withRequestTarget(string $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. @@ -444,7 +444,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. @@ -455,7 +455,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. @@ -487,7 +487,7 @@ 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; } } @@ -519,7 +519,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. @@ -541,7 +541,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. @@ -556,7 +556,7 @@ 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; } } @@ -612,7 +612,7 @@ interface ServerRequestInterface extends RequestInterface * * @return array */ - public function getServerParams(); + public function getServerParams(): array; /** * Retrieve cookies. @@ -624,7 +624,7 @@ public function getServerParams(); * * @return array */ - public function getCookieParams(); + public function getCookieParams(): array; /** * Return an instance with the specified cookies. @@ -643,7 +643,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. @@ -657,7 +657,7 @@ public function withCookieParams(array $cookies); * * @return array */ - public function getQueryParams(); + public function getQueryParams(): array; /** * Return an instance with the specified query string arguments. @@ -681,7 +681,7 @@ public function getQueryParams(); * $_GET. * @return static */ - public function withQueryParams(array $query); + public function withQueryParams(array $query): ServerRequestInterface; /** * Retrieve normalized file upload data. @@ -695,7 +695,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. @@ -708,7 +708,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. @@ -755,7 +755,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. @@ -768,7 +768,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. @@ -802,7 +802,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. @@ -818,7 +818,7 @@ 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; } } @@ -848,14 +848,14 @@ 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. * * @return void */ - public function close(); + public function close(): void; /** * Separates any underlying resources from the stream. @@ -871,7 +871,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 @@ -879,21 +879,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. @@ -907,7 +907,7 @@ public function isSeekable(); * 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. @@ -919,14 +919,14 @@ 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. * * @return bool */ - public function isWritable(); + public function isWritable(): bool; /** * Write data to the stream. @@ -935,14 +935,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. @@ -954,7 +954,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 @@ -963,7 +963,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. @@ -1010,7 +1010,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. @@ -1044,7 +1044,7 @@ public function getStream(); * @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. @@ -1055,7 +1055,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. @@ -1071,7 +1071,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. @@ -1086,7 +1086,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. @@ -1101,7 +1101,7 @@ 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; } } @@ -1144,7 +1144,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. @@ -1164,7 +1164,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. @@ -1181,7 +1181,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. @@ -1194,7 +1194,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. @@ -1211,7 +1211,7 @@ public function getHost(); * * @return null|int The URI port. */ - public function getPort(); + public function getPort(): ?int; /** * Retrieve the path component of the URI. @@ -1238,7 +1238,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. @@ -1260,7 +1260,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. @@ -1278,7 +1278,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. @@ -1295,7 +1295,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. @@ -1311,7 +1311,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. @@ -1325,7 +1325,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. @@ -1344,7 +1344,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. @@ -1368,7 +1368,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. @@ -1385,7 +1385,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. @@ -1401,7 +1401,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. @@ -1426,7 +1426,7 @@ public function withFragment(string $fragment); * @see http://tools.ietf.org/html/rfc3986#section-4.1 * @return string */ - public function __toString(); + public function __toString(): string; } } @@ -2513,11 +2513,19 @@ public function getContents(): string throw new \RuntimeException('Stream is detached'); } - if (false === $contents = @\stream_get_contents($this->stream)) { - throw new \RuntimeException('Unable to read stream contents: ' . (\error_get_last()['message'] ?? '')); - } + $exception = null; + + \set_error_handler(static function ($type, $message) use (&$exception) { + throw $exception = new \RuntimeException('Unable to read stream contents: ' . $message); + }); - return $contents; + try { + return \stream_get_contents($this->stream); + } catch (\Throwable $e) { + throw $e === $exception ? $e : new \RuntimeException('Unable to read stream contents: ' . $e->getMessage(), 0, $e); + } finally { + \restore_error_handler(); + } } /** @@ -3306,7 +3314,7 @@ public function fromGlobals(): ServerRequestInterface /** * {@inheritdoc} */ - public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], /*?array*/ $post = null, array $files = [], $body = null): ServerRequestInterface + public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], ?array $post = null, array $files = [], $body = null): ServerRequestInterface { $method = $this->getMethodFromEnv($server); $uri = $this->getUriFromEnvWithHTTP($server); @@ -3575,7 +3583,8 @@ public function fromArrays( array $server, array $headers = [], array $cookie = [], - array $get = [], /*?array*/ $post = null, + array $get = [], + ?array $post = null, array $files = [], $body = null ): ServerRequestInterface; diff --git a/composer.lock b/composer.lock index 1d8debad..16a96c2d 100644 --- a/composer.lock +++ b/composer.lock @@ -152,20 +152,20 @@ }, { "name": "psr/http-factory", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-factory.git", - "reference": "e616d01114759c4c489f93b099585439f795fe35" + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", - "reference": "e616d01114759c4c489f93b099585439f795fe35", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", "shasum": "" }, "require": { - "php": ">=7.0.0", + "php": ">=7.1", "psr/http-message": "^1.0 || ^2.0" }, "type": "library", @@ -189,7 +189,7 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", "keywords": [ "factory", "http", @@ -201,9 +201,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + "source": "https://github.com/php-fig/http-factory" }, - "time": "2023-04-10T20:10:41+00:00" + "time": "2024-04-15T12:06:14+00:00" }, { "name": "psr/http-message", @@ -386,5 +386,5 @@ "ext-mbstring": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.2.0" }