N°5122 - Update libs to new PHP requirements

This commit is contained in:
Molkobain
2022-08-08 14:10:26 +02:00
parent 30021d9236
commit 57c36d0e51
585 changed files with 62279 additions and 20427 deletions

View File

@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\StreamInterface;
@@ -7,10 +9,8 @@ use Psr\Http\Message\StreamInterface;
/**
* Stream decorator that can cache previously read bytes from a sequentially
* read stream.
*
* @final
*/
class CachingStream implements StreamInterface
final class CachingStream implements StreamInterface
{
use StreamDecoratorTrait;
@@ -20,6 +20,11 @@ class CachingStream implements StreamInterface
/** @var int Number of bytes to skip reading due to a write on the buffer */
private $skipReadBytes = 0;
/**
* @var StreamInterface
*/
private $stream;
/**
* We will treat the buffer object as the body of the stream
*
@@ -34,7 +39,7 @@ class CachingStream implements StreamInterface
$this->stream = $target ?: new Stream(Utils::tryFopen('php://temp', 'r+'));
}
public function getSize()
public function getSize(): ?int
{
$remoteSize = $this->remoteStream->getSize();
@@ -45,18 +50,18 @@ class CachingStream implements StreamInterface
return max($this->stream->getSize(), $remoteSize);
}
public function rewind()
public function rewind(): void
{
$this->seek(0);
}
public function seek($offset, $whence = SEEK_SET)
public function seek($offset, $whence = SEEK_SET): void
{
if ($whence == SEEK_SET) {
if ($whence === SEEK_SET) {
$byte = $offset;
} elseif ($whence == SEEK_CUR) {
} elseif ($whence === SEEK_CUR) {
$byte = $offset + $this->tell();
} elseif ($whence == SEEK_END) {
} elseif ($whence === SEEK_END) {
$size = $this->remoteStream->getSize();
if ($size === null) {
$size = $this->cacheEntireStream();
@@ -81,7 +86,7 @@ class CachingStream implements StreamInterface
}
}
public function read($length)
public function read($length): string
{
// Perform a regular read on any previously read data from the buffer
$data = $this->stream->read($length);
@@ -110,7 +115,7 @@ class CachingStream implements StreamInterface
return $data;
}
public function write($string)
public function write($string): int
{
// When appending to the end of the currently read stream, you'll want
// to skip bytes from being read from the remote stream to emulate
@@ -124,7 +129,7 @@ class CachingStream implements StreamInterface
return $this->stream->write($string);
}
public function eof()
public function eof(): bool
{
return $this->stream->eof() && $this->remoteStream->eof();
}
@@ -132,12 +137,13 @@ class CachingStream implements StreamInterface
/**
* Close both the remote stream and buffer stream
*/
public function close()
public function close(): void
{
$this->remoteStream->close() && $this->stream->close();
$this->remoteStream->close();
$this->stream->close();
}
private function cacheEntireStream()
private function cacheEntireStream(): int
{
$target = new FnStream(['write' => 'strlen']);
Utils::copyToStream($this, $target);