Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow psr/http-message v2.0 (1.x) #541

Open
wants to merge 10 commits into
base: 1.x
Choose a base branch
from
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
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@
"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": "^1.0 || ^2.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/reactphp-ssh-proxy": "^1.4",
"clue/socks-react": "^1.4",
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"psr/http-message": "^1.0 || ^2.0",
"react/async": "^4.2 || ^3 || ^2",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.11"
Expand Down
55 changes: 44 additions & 11 deletions src/Io/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ protected function __construct($protocolVersion, array $headers, StreamInterface
$this->body = $body;
}

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

public function withProtocolVersion($version)
/**
* @inheritdoc
*/
public function withProtocolVersion(string $version): self
{
if ((string) $version === $this->protocolVersion) {
return $this;
Expand All @@ -82,28 +88,43 @@ public function withProtocolVersion($version)
return $message;
}

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

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

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

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

public function withHeader($name, $value)
/**
* @inheritdoc
*/
public function withHeader(string $name, $value): self
{
if ($value === array()) {
return $this->withoutHeader($name);
Expand Down Expand Up @@ -131,7 +152,10 @@ public function withHeader($name, $value)
return $message;
}

public function withAddedHeader($name, $value)
/**
* @inheritdoc
*/
public function withAddedHeader(string $name, $value): self
{
if ($value === array()) {
return $this;
Expand All @@ -140,7 +164,10 @@ public function withAddedHeader($name, $value)
return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : array($value)));
}

public function withoutHeader($name)
/**
* @inheritdoc
*/
public function withoutHeader(string $name): self
{
$lower = \strtolower($name);
if (!isset($this->headerNamesLowerCase[$lower])) {
Expand All @@ -153,12 +180,18 @@ public function withoutHeader($name)
return $message;
}

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

public function withBody(StreamInterface $body)
/**
* @inheritdoc
*/
public function withBody(StreamInterface $body): self
{
if ($body === $this->body) {
return $this;
Expand Down
30 changes: 24 additions & 6 deletions src/Io/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ protected function __construct(
$this->uri = $uri;
}

public function getRequestTarget()
/**
* @inheritdoc
*/
public function getRequestTarget(): string
{
if ($this->requestTarget !== null) {
return $this->requestTarget;
Expand All @@ -88,7 +91,10 @@ public function getRequestTarget()
return $target;
}

public function withRequestTarget($requestTarget)
/**
* @inheritdoc
*/
public function withRequestTarget(string $requestTarget): RequestInterface
{
if ((string) $requestTarget === $this->requestTarget) {
return $this;
Expand All @@ -100,12 +106,18 @@ public function withRequestTarget($requestTarget)
return $request;
}

public function getMethod()
/**
* @inheritdoc
*/
public function getMethod(): string
{
return $this->method;
}

public function withMethod($method)
/**
* @inheritdoc
*/
public function withMethod(string $method): RequestInterface
{
if ((string) $method === $this->method) {
return $this;
Expand All @@ -117,12 +129,18 @@ public function withMethod($method)
return $request;
}

public function getUri()
/**
* @inheritdoc
*/
public function getUri(): UriInterface
{
return $this->uri;
}

public function withUri(UriInterface $uri, $preserveHost = false)
/**
* @inheritdoc
*/
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface
{
if ($uri === $this->uri) {
return $this;
Expand Down
73 changes: 59 additions & 14 deletions src/Io/BufferedBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public function __construct($buffer)
$this->buffer = $buffer;
}

public function __toString()
/**
* @inheritdoc
*/
public function __toString(): string
{
if ($this->closed) {
return '';
Expand All @@ -34,26 +37,38 @@ public function __toString()
return $this->getContents();
}

public function close()
/**
* @inheritdoc
*/
public function close(): void
{
$this->buffer = '';
$this->position = 0;
$this->closed = true;
}

/**
* @inheritdoc
*/
public function detach()
{
$this->close();

return null;
}

public function getSize()
/**
* @inheritdoc
*/
public function getSize(): ?int
{
return $this->closed ? null : \strlen($this->buffer);
}

public function tell()
/**
* @inheritdoc
*/
public function tell(): int
{
if ($this->closed) {
throw new \RuntimeException('Unable to tell position of closed stream');
Expand All @@ -62,17 +77,26 @@ public function tell()
return $this->position;
}

public function eof()
/**
* @inheritdoc
*/
public function eof(): bool
{
return $this->position >= \strlen($this->buffer);
}

public function isSeekable()
/**
* @inheritdoc
*/
public function isSeekable(): bool
{
return !$this->closed;
}

public function seek($offset, $whence = \SEEK_SET)
/**
* @inheritdoc
*/
public function seek($offset, $whence = \SEEK_SET): void
{
if ($this->closed) {
throw new \RuntimeException('Unable to seek on closed stream');
Expand All @@ -96,17 +120,26 @@ public function seek($offset, $whence = \SEEK_SET)
}
}

public function rewind()
/**
* @inheritdoc
*/
public function rewind(): void
{
$this->seek(0);
}

public function isWritable()
/**
* @inheritdoc
*/
public function isWritable(): bool
{
return !$this->closed;
}

public function write($string)
/**
* @inheritdoc
*/
public function write(string $string): int
{
if ($this->closed) {
throw new \RuntimeException('Unable to write to closed stream');
Expand All @@ -127,12 +160,18 @@ public function write($string)
return $len;
}

public function isReadable()
/**
* @inheritdoc
*/
public function isReadable(): bool
{
return !$this->closed;
}

public function read($length)
/**
* @inheritdoc
*/
public function read(int $length): string
{
if ($this->closed) {
throw new \RuntimeException('Unable to read from closed stream');
Expand All @@ -156,7 +195,10 @@ public function read($length)
return \substr($this->buffer, $pos, $length);
}

public function getContents()
/**
* @inheritdoc
*/
public function getContents(): string
{
if ($this->closed) {
throw new \RuntimeException('Unable to read from closed stream');
Expand All @@ -172,7 +214,10 @@ public function getContents()
return \substr($this->buffer, $pos);
}

public function getMetadata($key = null)
/**
* @inheritdoc
*/
public function getMetadata($key = null): ?array
{
return $key === null ? array() : null;
}
Expand Down
Loading
Loading