From d38d9f7f97c653fd76d09bdb3b1532c7e8969d55 Mon Sep 17 00:00:00 2001 From: Marek Fojtl Date: Tue, 5 Aug 2025 10:44:13 +0200 Subject: [PATCH 1/6] Update psr/http-message dependency to version 2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 809e81c9..72c5f7a8 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "php": ">=7.1", "evenement/evenement": "^3.0 || ^2.0 || ^1.0", "fig/http-message-util": "^1.1", - "psr/http-message": "^1.0", + "psr/http-message": "^2.0", "react/event-loop": "^1.2", "react/promise": "^3.2 || ^2.3 || ^1.2.1", "react/socket": "^1.16", From 0e4519e7d1bfabddb2e29107120218ed88b1bb59 Mon Sep 17 00:00:00 2001 From: Marek Fojtl Date: Tue, 5 Aug 2025 10:52:32 +0200 Subject: [PATCH 2/6] Rename package from react/http to polyweb-cz/react-http --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 72c5f7a8..e315d2a5 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "react/http", + "name": "polyweb-cz/react-http", "description": "Event-driven, streaming HTTP client and server implementation for ReactPHP", "keywords": ["HTTP client", "HTTP server", "HTTP", "HTTPS", "event-driven", "streaming", "client", "server", "PSR-7", "async", "ReactPHP"], "license": "MIT", From 176d83095b124ca76f9816f9c9fedfbd662dfaf0 Mon Sep 17 00:00:00 2001 From: Marek Fojtl Date: Tue, 5 Aug 2025 11:29:47 +0200 Subject: [PATCH 3/6] Add type hints to methods in AbstractMessage class --- src/Io/AbstractMessage.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Io/AbstractMessage.php b/src/Io/AbstractMessage.php index 232a5442..3d2b534b 100644 --- a/src/Io/AbstractMessage.php +++ b/src/Io/AbstractMessage.php @@ -65,12 +65,12 @@ protected function __construct($protocolVersion, array $headers, StreamInterface $this->body = $body; } - public function getProtocolVersion() + public function getProtocolVersion(): string { return $this->protocolVersion; } - public function withProtocolVersion($version) + public function withProtocolVersion(string $version): MessageInterface { if ((string) $version === $this->protocolVersion) { return $this; @@ -82,28 +82,28 @@ public function withProtocolVersion($version) return $message; } - public function getHeaders() + public function getHeaders(): array { return $this->headers; } - public function hasHeader($name) + public function hasHeader(string $name): bool { return isset($this->headerNamesLowerCase[\strtolower($name)]); } - public function getHeader($name) + public function getHeader(string $name): array { $lower = \strtolower($name); return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : []; } - public function getHeaderLine($name) + public function getHeaderLine(string $name): string { return \implode(', ', $this->getHeader($name)); } - public function withHeader($name, $value) + public function withHeader(string $name, $value): MessageInterface { if ($value === []) { return $this->withoutHeader($name); @@ -131,7 +131,7 @@ public function withHeader($name, $value) return $message; } - public function withAddedHeader($name, $value) + public function withAddedHeader(string $name, $value): MessageInterface { if ($value === []) { return $this; @@ -140,7 +140,7 @@ public function withAddedHeader($name, $value) return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : [$value])); } - public function withoutHeader($name) + public function withoutHeader(string $name): MessageInterface { $lower = \strtolower($name); if (!isset($this->headerNamesLowerCase[$lower])) { @@ -153,12 +153,12 @@ public function withoutHeader($name) return $message; } - public function getBody() + public function getBody(): StreamInterface { return $this->body; } - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): MessageInterface { if ($body === $this->body) { return $this; From e16d960ab7ea19b238cd16dd17b604a6b92c47bc Mon Sep 17 00:00:00 2001 From: Marek Fojtl Date: Tue, 5 Aug 2025 13:46:14 +0200 Subject: [PATCH 4/6] Add type hints to methods in AbstractRequest, BufferedBody, Response, ServerRequest, UploadedFile, and Uri classes --- src/Io/AbstractRequest.php | 12 ++++++------ src/Io/BufferedBody.php | 28 ++++++++++++++-------------- src/Io/UploadedFile.php | 30 ++++++------------------------ src/Message/Response.php | 6 +++--- src/Message/ServerRequest.php | 24 ++++++++++++------------ src/Message/Uri.php | 30 +++++++++++++++--------------- 6 files changed, 56 insertions(+), 74 deletions(-) diff --git a/src/Io/AbstractRequest.php b/src/Io/AbstractRequest.php index 1182f7ab..335e2329 100644 --- a/src/Io/AbstractRequest.php +++ b/src/Io/AbstractRequest.php @@ -71,7 +71,7 @@ protected function __construct( $this->uri = $uri; } - public function getRequestTarget() + public function getRequestTarget(): string { if ($this->requestTarget !== null) { return $this->requestTarget; @@ -88,7 +88,7 @@ public function getRequestTarget() return $target; } - public function withRequestTarget($requestTarget) + public function withRequestTarget(string $requestTarget): RequestInterface { if ((string) $requestTarget === $this->requestTarget) { return $this; @@ -100,12 +100,12 @@ public function withRequestTarget($requestTarget) return $request; } - public function getMethod() + public function getMethod(): string { return $this->method; } - public function withMethod($method) + public function withMethod(string $method): RequestInterface { if ((string) $method === $this->method) { return $this; @@ -117,12 +117,12 @@ public function withMethod($method) return $request; } - public function getUri() + public function getUri(): UriInterface { return $this->uri; } - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface { if ($uri === $this->uri) { return $this; diff --git a/src/Io/BufferedBody.php b/src/Io/BufferedBody.php index 9b1d9887..eee907e4 100644 --- a/src/Io/BufferedBody.php +++ b/src/Io/BufferedBody.php @@ -23,7 +23,7 @@ public function __construct($buffer) $this->buffer = $buffer; } - public function __toString() + public function __toString(): string { if ($this->closed) { return ''; @@ -34,7 +34,7 @@ public function __toString() return $this->getContents(); } - public function close() + public function close(): void { $this->buffer = ''; $this->position = 0; @@ -48,12 +48,12 @@ public function detach() return null; } - public function getSize() + public function getSize(): ?int { return $this->closed ? null : \strlen($this->buffer); } - public function tell() + public function tell(): int { if ($this->closed) { throw new \RuntimeException('Unable to tell position of closed stream'); @@ -62,17 +62,17 @@ public function tell() return $this->position; } - public function eof() + public function eof(): bool { return $this->position >= \strlen($this->buffer); } - public function isSeekable() + public function isSeekable(): bool { return !$this->closed; } - public function seek($offset, $whence = \SEEK_SET) + public function seek(int $offset, int $whence = \SEEK_SET): void { if ($this->closed) { throw new \RuntimeException('Unable to seek on closed stream'); @@ -96,17 +96,17 @@ public function seek($offset, $whence = \SEEK_SET) } } - public function rewind() + public function rewind(): void { $this->seek(0); } - public function isWritable() + public function isWritable(): bool { return !$this->closed; } - public function write($string) + public function write(string $string): int { if ($this->closed) { throw new \RuntimeException('Unable to write to closed stream'); @@ -127,12 +127,12 @@ public function write($string) return $len; } - public function isReadable() + public function isReadable(): bool { return !$this->closed; } - public function read($length) + public function read(int $length): string { if ($this->closed) { throw new \RuntimeException('Unable to read from closed stream'); @@ -156,7 +156,7 @@ public function read($length) return \substr($this->buffer, $pos, $length); } - public function getContents() + public function getContents(): string { if ($this->closed) { throw new \RuntimeException('Unable to read from closed stream'); @@ -172,7 +172,7 @@ public function getContents() return \substr($this->buffer, $pos); } - public function getMetadata($key = null) + public function getMetadata(?string $key = null) { return $key === null ? [] : null; } diff --git a/src/Io/UploadedFile.php b/src/Io/UploadedFile.php index b0d0dd98..144512bc 100644 --- a/src/Io/UploadedFile.php +++ b/src/Io/UploadedFile.php @@ -76,10 +76,7 @@ public function __construct(StreamInterface $stream, $size, $error, $filename, $ $this->mediaType = $mediaType; } - /** - * {@inheritdoc} - */ - public function getStream() + public function getStream(): StreamInterface { if ($this->error !== \UPLOAD_ERR_OK) { throw new RuntimeException('Cannot retrieve stream due to upload error'); @@ -88,42 +85,27 @@ public function getStream() return $this->stream; } - /** - * {@inheritdoc} - */ - public function moveTo($targetPath) + public function moveTo(string $targetPath): void { throw new RuntimeException('Not implemented'); } - /** - * {@inheritdoc} - */ - public function getSize() + public function getSize(): ?int { return $this->size; } - /** - * {@inheritdoc} - */ - public function getError() + public function getError(): int { return $this->error; } - /** - * {@inheritdoc} - */ - public function getClientFilename() + public function getClientFilename(): ?string { return $this->filename; } - /** - * {@inheritdoc} - */ - public function getClientMediaType() + public function getClientMediaType(): ?string { return $this->mediaType; } diff --git a/src/Message/Response.php b/src/Message/Response.php index 93557fab..5b139600 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -319,12 +319,12 @@ public function __construct( $this->reasonPhrase = ($reason !== '' && $reason !== null) ? (string) $reason : self::getReasonPhraseForStatusCode($status); } - public function getStatusCode() + public function getStatusCode(): int { return $this->statusCode; } - public function withStatus($code, $reasonPhrase = '') + public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface { if ((string) $reasonPhrase === '') { $reasonPhrase = self::getReasonPhraseForStatusCode($code); @@ -341,7 +341,7 @@ public function withStatus($code, $reasonPhrase = '') return $response; } - public function getReasonPhrase() + public function getReasonPhrase(): string { return $this->reasonPhrase; } diff --git a/src/Message/ServerRequest.php b/src/Message/ServerRequest.php index da0d76ab..0cdc32b8 100644 --- a/src/Message/ServerRequest.php +++ b/src/Message/ServerRequest.php @@ -87,41 +87,41 @@ public function __construct( } } - public function getServerParams() + public function getServerParams(): array { return $this->serverParams; } - public function getCookieParams() + public function getCookieParams(): array { return $this->cookies; } - public function withCookieParams(array $cookies) + public function withCookieParams(array $cookies): ServerRequestInterface { $new = clone $this; $new->cookies = $cookies; return $new; } - public function getQueryParams() + public function getQueryParams(): array { return $this->queryParams; } - public function withQueryParams(array $query) + public function withQueryParams(array $query): ServerRequestInterface { $new = clone $this; $new->queryParams = $query; return $new; } - public function getUploadedFiles() + public function getUploadedFiles(): array { return $this->fileParams; } - public function withUploadedFiles(array $uploadedFiles) + public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface { $new = clone $this; $new->fileParams = $uploadedFiles; @@ -133,19 +133,19 @@ public function getParsedBody() return $this->parsedBody; } - public function withParsedBody($data) + public function withParsedBody($data): ServerRequestInterface { $new = clone $this; $new->parsedBody = $data; return $new; } - public function getAttributes() + public function getAttributes(): array { return $this->attributes; } - public function getAttribute($name, $default = null) + public function getAttribute(string $name, $default = null) { if (!\array_key_exists($name, $this->attributes)) { return $default; @@ -153,14 +153,14 @@ public function getAttribute($name, $default = null) return $this->attributes[$name]; } - public function withAttribute($name, $value) + public function withAttribute(string $name, $value): ServerRequestInterface { $new = clone $this; $new->attributes[$name] = $value; return $new; } - public function withoutAttribute($name) + public function withoutAttribute(string $name): ServerRequestInterface { $new = clone $this; unset($new->attributes[$name]); diff --git a/src/Message/Uri.php b/src/Message/Uri.php index 661f90c4..a4b16b11 100644 --- a/src/Message/Uri.php +++ b/src/Message/Uri.php @@ -79,12 +79,12 @@ public function __construct($uri) } } - public function getScheme() + public function getScheme(): string { return $this->scheme; } - public function getAuthority() + public function getAuthority(): string { if ($this->host === '') { return ''; @@ -93,37 +93,37 @@ public function getAuthority() return ($this->userInfo !== '' ? $this->userInfo . '@' : '') . $this->host . ($this->port !== null ? ':' . $this->port : ''); } - public function getUserInfo() + public function getUserInfo(): string { return $this->userInfo; } - public function getHost() + public function getHost(): string { return $this->host; } - public function getPort() + public function getPort(): ?int { return $this->port; } - public function getPath() + public function getPath(): string { return $this->path; } - public function getQuery() + public function getQuery(): string { return $this->query; } - public function getFragment() + public function getFragment(): string { return $this->fragment; } - public function withScheme($scheme) + public function withScheme(string $scheme): UriInterface { $scheme = \strtolower($scheme); if ($scheme === $this->scheme) { @@ -144,7 +144,7 @@ public function withScheme($scheme) return $new; } - public function withUserInfo($user, $password = null) + public function withUserInfo(string $user, ?string $password = null): UriInterface { $userInfo = $this->encode($user, \PHP_URL_USER) . ($password !== null ? ':' . $this->encode($password, \PHP_URL_PASS) : ''); if ($userInfo === $this->userInfo) { @@ -157,7 +157,7 @@ public function withUserInfo($user, $password = null) return $new; } - public function withHost($host) + public function withHost(string $host): UriInterface { $host = \strtolower($host); if ($host === $this->host) { @@ -174,7 +174,7 @@ public function withHost($host) return $new; } - public function withPort($port) + public function withPort(?int $port): UriInterface { $port = $port === null ? null : (int) $port; if (($port === 80 && $this->scheme === 'http') || ($port === 443 && $this->scheme === 'https')) { @@ -195,7 +195,7 @@ public function withPort($port) return $new; } - public function withPath($path) + public function withPath(string $path): UriInterface { $path = $this->encode($path, \PHP_URL_PATH); if ($path === $this->path) { @@ -208,7 +208,7 @@ public function withPath($path) return $new; } - public function withQuery($query) + public function withQuery(string $query): UriInterface { $query = $this->encode($query, \PHP_URL_QUERY); if ($query === $this->query) { @@ -221,7 +221,7 @@ public function withQuery($query) return $new; } - public function withFragment($fragment) + public function withFragment(string $fragment): UriInterface { $fragment = $this->encode($fragment, \PHP_URL_FRAGMENT); if ($fragment === $this->fragment) { From a76d6b17726d8e8b6f3cedf2ebb3a663d09daea8 Mon Sep 17 00:00:00 2001 From: Marek Fojtl Date: Tue, 5 Aug 2025 14:11:16 +0200 Subject: [PATCH 5/6] Add type hints to methods in HttpBodyStream class --- src/Io/HttpBodyStream.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Io/HttpBodyStream.php b/src/Io/HttpBodyStream.php index 8be9b854..810898ab 100644 --- a/src/Io/HttpBodyStream.php +++ b/src/Io/HttpBodyStream.php @@ -45,29 +45,29 @@ public function __construct(ReadableStreamInterface $input, $size) $this->input->on('close', [$this, 'close']); } - public function isReadable() + public function isReadable(): bool { return !$this->closed && $this->input->isReadable(); } - public function pause() + public function pause(): void { $this->input->pause(); } - public function resume() + public function resume(): void { $this->input->resume(); } - public function pipe(WritableStreamInterface $dest, array $options = []) + public function pipe(WritableStreamInterface $dest, array $options = []): WritableStreamInterface { Util::pipe($this, $dest, $options); return $dest; } - public function close() + public function close(): void { if ($this->closed) { return; @@ -81,13 +81,13 @@ public function close() $this->removeAllListeners(); } - public function getSize() + public function getSize(): ?int { return $this->size; } /** @ignore */ - public function __toString() + public function __toString(): string { return ''; } @@ -99,61 +99,61 @@ public function detach() } /** @ignore */ - public function tell() + public function tell(): int { throw new \BadMethodCallException(); } /** @ignore */ - public function eof() + public function eof(): bool { throw new \BadMethodCallException(); } /** @ignore */ - public function isSeekable() + public function isSeekable(): bool { return false; } /** @ignore */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { throw new \BadMethodCallException(); } /** @ignore */ - public function rewind() + public function rewind(): void { throw new \BadMethodCallException(); } /** @ignore */ - public function isWritable() + public function isWritable(): bool { return false; } /** @ignore */ - public function write($string) + public function write(string $string): int { throw new \BadMethodCallException(); } /** @ignore */ - public function read($length) + public function read(int $length): string { throw new \BadMethodCallException(); } /** @ignore */ - public function getContents() + public function getContents(): string { return ''; } /** @ignore */ - public function getMetadata($key = null) + public function getMetadata(?string $key = null) { return null; } From 5b41a32bef11be687c888db77ec6e4fa0aa45059 Mon Sep 17 00:00:00 2001 From: Marek Fojtl Date: Tue, 5 Aug 2025 14:21:59 +0200 Subject: [PATCH 6/6] Add type hints to methods in EmptyBodyStream class --- src/Io/EmptyBodyStream.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Io/EmptyBodyStream.php b/src/Io/EmptyBodyStream.php index 7f9c8ad0..94a8a8dd 100644 --- a/src/Io/EmptyBodyStream.php +++ b/src/Io/EmptyBodyStream.php @@ -29,29 +29,29 @@ class EmptyBodyStream extends EventEmitter implements StreamInterface, ReadableS { private $closed = false; - public function isReadable() + public function isReadable(): bool { return !$this->closed; } - public function pause() + public function pause(): void { // NOOP } - public function resume() + public function resume(): void { // NOOP } - public function pipe(WritableStreamInterface $dest, array $options = []) + public function pipe(WritableStreamInterface $dest, array $options = []): WritableStreamInterface { Util::pipe($this, $dest, $options); return $dest; } - public function close() + public function close(): void { if ($this->closed) { return; @@ -63,13 +63,13 @@ public function close() $this->removeAllListeners(); } - public function getSize() + public function getSize(): ?int { return 0; } /** @ignore */ - public function __toString() + public function __toString(): string { return ''; } @@ -81,61 +81,61 @@ public function detach() } /** @ignore */ - public function tell() + public function tell(): int { throw new \BadMethodCallException(); } /** @ignore */ - public function eof() + public function eof(): bool { throw new \BadMethodCallException(); } /** @ignore */ - public function isSeekable() + public function isSeekable(): bool { return false; } /** @ignore */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { throw new \BadMethodCallException(); } /** @ignore */ - public function rewind() + public function rewind(): void { throw new \BadMethodCallException(); } /** @ignore */ - public function isWritable() + public function isWritable(): bool { return false; } /** @ignore */ - public function write($string) + public function write(string $string): int { throw new \BadMethodCallException(); } /** @ignore */ - public function read($length) + public function read(int $length): string { throw new \BadMethodCallException(); } /** @ignore */ - public function getContents() + public function getContents(): string { return ''; } /** @ignore */ - public function getMetadata($key = null) + public function getMetadata(?string $key = null) { return ($key === null) ? [] : null; }