Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php:
- 8.4
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"php": ">=5.3.0",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"fig/http-message-util": "^1.1",
"psr/http-message": "^1.0",
"psr/http-message": "^2.0 || ^1.0",
"react/event-loop": "^1.2",
"react/promise": "^3.2 || ^2.3 || ^1.2.1",
"react/socket": "^1.16",
"react/stream": "^1.4"
},
"require-dev": {
"clue/http-proxy-react": "^1.8",
"clue/http-proxy-react": "^1.10",
"clue/reactphp-ssh-proxy": "^1.4",
"clue/socks-react": "^1.4",
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"phpunit/phpunit": "^9.6 || ^8.5 || ^5.7 || ^4.8.36",
"react/async": "^4.2 || ^3 || ^2",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.11"
Expand Down
5 changes: 5 additions & 0 deletions src/Io/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\MessageInterface','withProtocolVersion');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* [Internal] Abstract HTTP message base class (PSR-7)
*
Expand Down Expand Up @@ -170,3 +172,6 @@ public function withBody(StreamInterface $body)
return $message;
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\AbstractMessage', __NAMESPACE__ . '\\AbstractMessage');
}
5 changes: 5 additions & 0 deletions src/Io/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Psr\Http\Message\UriInterface;
use React\Http\Message\Uri;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\RequestInterface','withRequestTarget');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* [Internal] Abstract HTTP request base class (PSR-7)
*
Expand Down Expand Up @@ -154,3 +156,6 @@ public function withUri(UriInterface $uri, $preserveHost = false)
return $request;
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\AbstractRequest', __NAMESPACE__ . '\\AbstractRequest');
}
5 changes: 5 additions & 0 deletions src/Io/BufferedBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Psr\Http\Message\StreamInterface;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\StreamInterface','eof');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* [Internal] PSR-7 message body implementation using an in-memory buffer
*
Expand Down Expand Up @@ -177,3 +179,6 @@ public function getMetadata($key = null)
return $key === null ? array() : null;
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\BufferedBody', __NAMESPACE__ . '\\BufferedBody');
}
5 changes: 5 additions & 0 deletions src/Io/EmptyBodyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use React\Stream\Util;
use React\Stream\WritableStreamInterface;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\StreamInterface','eof');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* [Internal] Bridge between an empty StreamInterface from PSR-7 and ReadableStreamInterface from ReactPHP
*
Expand Down Expand Up @@ -140,3 +142,6 @@ public function getMetadata($key = null)
return ($key === null) ? array() : null;
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\EmptyBodyStream', __NAMESPACE__ . '\\EmptyBodyStream');
}
5 changes: 5 additions & 0 deletions src/Io/HttpBodyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use React\Stream\Util;
use React\Stream\WritableStreamInterface;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\StreamInterface','eof');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* [Internal] Bridge between StreamInterface from PSR-7 and ReadableStreamInterface from ReactPHP
*
Expand Down Expand Up @@ -180,3 +182,6 @@ public function handleEnd()
}
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\HttpBodyStream', __NAMESPACE__ . '\\HttpBodyStream');
}
5 changes: 5 additions & 0 deletions src/Io/ReadableBodyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use React\Stream\Util;
use React\Stream\WritableStreamInterface;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\StreamInterface','eof');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* @internal
*/
Expand Down Expand Up @@ -151,3 +153,6 @@ public function handleEnd()
$this->close();
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\ReadableBodyStream', __NAMESPACE__ . '\\ReadableBodyStream');
}
7 changes: 6 additions & 1 deletion src/Io/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use InvalidArgumentException;
use RuntimeException;

$reflectedMethod = new \ReflectionMethod('\Psr\Http\Message\UploadedFileInterface','getStream');
if (!(PHP_VERSION_ID >= 70000 && $reflectedMethod->hasReturnType())) {
/**
* [Internal] Implementation of the PSR-7 `UploadedFileInterface`
*
Expand All @@ -18,7 +20,7 @@
* @see UploadedFileInterface
* @internal
*/
final class UploadedFile implements UploadedFileInterface
class UploadedFile implements UploadedFileInterface
{
/**
* @var StreamInterface
Expand Down Expand Up @@ -128,3 +130,6 @@ public function getClientMediaType()
return $this->mediaType;
}
}
} else {
class_alias(__NAMESPACE__ . '\\V2\\UploadedFile', __NAMESPACE__ . '\\UploadedFile');
}
179 changes: 179 additions & 0 deletions src/Io/V2/AbstractMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace React\Http\Io\V2;

use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;

/**
* [Internal] Abstract HTTP message base class (PSR-7)
*
* @internal
* @see MessageInterface
*
* @deprecated Do not reference this FQCN directly. Not a runtime deprecation:
* when psr/http-message v2 is installed this class is the
* implementation behind the public name. Marked deprecated so
* tooling suggests the aliased class instead (see sibling file).
* @see \React\Http\Io\AbstractMessage
* @see ../AbstractMessage.php
*/
abstract class AbstractMessage implements MessageInterface
{
/**
* [Internal] Regex used to match all request header fields into an array, thanks to @kelunik for checking the HTTP specs and coming up with this regex
*
* @internal
* @var string
*/
const REGEX_HEADERS = '/^([^()<>@,;:\\\"\/\[\]?={}\x00-\x20\x7F]++):[\x20\x09]*+((?:[\x20\x09]*+[\x21-\x7E\x80-\xFF]++)*+)[\x20\x09]*+[\r]?+\n/m';

/** @var array<string,string[]> */
private $headers = array();

/** @var array<string,string> */
private $headerNamesLowerCase = array();

/** @var string */
private $protocolVersion;

/** @var StreamInterface */
private $body;

/**
* @param string $protocolVersion
* @param array<string,string|string[]> $headers
* @param StreamInterface $body
*/
protected function __construct($protocolVersion, array $headers, StreamInterface $body)
{
foreach ($headers as $name => $value) {
if ($value !== array()) {
if (\is_array($value)) {
foreach ($value as &$one) {
$one = (string) $one;
}
} else {
$value = array((string) $value);
}

$lower = \strtolower($name);
if (isset($this->headerNamesLowerCase[$lower])) {
$value = \array_merge($this->headers[$this->headerNamesLowerCase[$lower]], $value);
unset($this->headers[$this->headerNamesLowerCase[$lower]]);
}

$this->headers[$name] = $value;
$this->headerNamesLowerCase[$lower] = $name;
}
}

$this->protocolVersion = (string) $protocolVersion;
$this->body = $body;
}

public function getProtocolVersion(): string
{
return $this->protocolVersion;
}

public function withProtocolVersion(string $version): MessageInterface
{
if ((string) $version === $this->protocolVersion) {
return $this;
}

$message = clone $this;
$message->protocolVersion = (string) $version;

return $message;
}

public function getHeaders(): array
{
return $this->headers;
}

public function hasHeader(string $name): bool
{
return isset($this->headerNamesLowerCase[\strtolower($name)]);
}

public function getHeader(string $name): array
{
$lower = \strtolower($name);
return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : array();
}

public function getHeaderLine(string $name): string
{
return \implode(', ', $this->getHeader($name));
}

public function withHeader(string $name, $value): MessageInterface
{
if ($value === array()) {
return $this->withoutHeader($name);
} elseif (\is_array($value)) {
foreach ($value as &$one) {
$one = (string) $one;
}
} else {
$value = array((string) $value);
}

$lower = \strtolower($name);
if (isset($this->headerNamesLowerCase[$lower]) && $this->headerNamesLowerCase[$lower] === (string) $name && $this->headers[$this->headerNamesLowerCase[$lower]] === $value) {
return $this;
}

$message = clone $this;
if (isset($message->headerNamesLowerCase[$lower])) {
unset($message->headers[$message->headerNamesLowerCase[$lower]]);
}

$message->headers[$name] = $value;
$message->headerNamesLowerCase[$lower] = $name;

return $message;
}

public function withAddedHeader(string $name, $value): MessageInterface
{
if ($value === array()) {
return $this;
}

return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : array($value)));
}

public function withoutHeader(string $name): MessageInterface
{
$lower = \strtolower($name);
if (!isset($this->headerNamesLowerCase[$lower])) {
return $this;
}

$message = clone $this;
unset($message->headers[$message->headerNamesLowerCase[$lower]], $message->headerNamesLowerCase[$lower]);

return $message;
}

public function getBody(): StreamInterface
{
return $this->body;
}

public function withBody(StreamInterface $body): MessageInterface
{
if ($body === $this->body) {
return $this;
}

$message = clone $this;
$message->body = $body;

return $message;
}
}
Loading
Loading