mirror of
https://github.com/itflow-org/itflow
synced 2026-08-16 20:45:12 +00:00
Update imapengine dependancies too
This commit is contained in:
99
libs/vendor/guzzlehttp/psr7/src/LimitStream.php
vendored
99
libs/vendor/guzzlehttp/psr7/src/LimitStream.php
vendored
@@ -12,15 +12,15 @@ use Psr\Http\Message\StreamInterface;
|
||||
final class LimitStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
use NonSerializableStreamTrait;
|
||||
|
||||
/** @var int Offset to start reading from */
|
||||
private $offset;
|
||||
private int $offset;
|
||||
|
||||
/** @var int Limit the number of bytes that can be read */
|
||||
private $limit;
|
||||
private int $limit;
|
||||
|
||||
/** @var StreamInterface */
|
||||
private $stream;
|
||||
private StreamInterface $stream;
|
||||
|
||||
/**
|
||||
* @param StreamInterface $stream Stream to wrap
|
||||
@@ -51,7 +51,7 @@ final class LimitStream implements StreamInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->stream->tell() >= $this->offset + $this->limit;
|
||||
return $this->stream->tell() >= Integers::add($this->offset, $this->limit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,26 +75,8 @@ final class LimitStream implements StreamInterface
|
||||
/**
|
||||
* Allow for a bounded seek on the read limited stream
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET): void
|
||||
public function seek(int $offset, int $whence = SEEK_SET): void
|
||||
{
|
||||
if (!\is_int($offset)) {
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/psr7',
|
||||
'2.11',
|
||||
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
|
||||
\get_debug_type($offset)
|
||||
);
|
||||
}
|
||||
|
||||
if (!\is_int($whence)) {
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/psr7',
|
||||
'2.11',
|
||||
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
|
||||
\get_debug_type($whence)
|
||||
);
|
||||
}
|
||||
|
||||
if ($whence !== SEEK_SET || $offset < 0) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Cannot seek to offset %s with whence %s',
|
||||
@@ -103,11 +85,12 @@ final class LimitStream implements StreamInterface
|
||||
));
|
||||
}
|
||||
|
||||
$offset += $this->offset;
|
||||
$offset = Integers::add($this->offset, $offset);
|
||||
|
||||
if ($this->limit !== -1) {
|
||||
if ($offset > $this->offset + $this->limit) {
|
||||
$offset = $this->offset + $this->limit;
|
||||
$upperBound = Integers::add($this->offset, $this->limit);
|
||||
if ($offset > $upperBound) {
|
||||
$offset = $upperBound;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,17 +114,48 @@ final class LimitStream implements StreamInterface
|
||||
*/
|
||||
public function setOffset(int $offset): void
|
||||
{
|
||||
$offset = Integers::assertNonNegativeInteger($offset, 'Offset');
|
||||
|
||||
$current = $this->stream->tell();
|
||||
|
||||
if ($current !== $offset) {
|
||||
// If the stream cannot seek to the offset position, then read to it
|
||||
if ($this->stream->isSeekable()) {
|
||||
$this->stream->seek($offset);
|
||||
} elseif ($current > $offset) {
|
||||
throw new \RuntimeException("Could not seek to stream offset $offset");
|
||||
} else {
|
||||
$this->stream->read($offset - $current);
|
||||
if ($current === $offset) {
|
||||
$this->offset = $offset;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the stream cannot seek to the offset position, then read to it.
|
||||
if ($this->stream->isSeekable()) {
|
||||
$this->stream->seek($offset);
|
||||
$this->offset = $offset;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($current > $offset) {
|
||||
throw new \RuntimeException("Could not seek to stream offset $offset");
|
||||
}
|
||||
|
||||
while ($current < $offset) {
|
||||
if ($this->stream->eof()) {
|
||||
$this->offset = $current;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->stream->read($offset - $current);
|
||||
|
||||
if ($result === '') {
|
||||
if ($this->stream->eof()) {
|
||||
$this->offset = $current;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \RuntimeException("Could not seek to stream offset $offset");
|
||||
}
|
||||
|
||||
$current = Integers::add($current, strlen($result));
|
||||
}
|
||||
|
||||
$this->offset = $offset;
|
||||
@@ -156,18 +170,13 @@ final class LimitStream implements StreamInterface
|
||||
*/
|
||||
public function setLimit(int $limit): void
|
||||
{
|
||||
$this->limit = $limit;
|
||||
$this->limit = Integers::assertLimitInteger($limit, 'Limit');
|
||||
}
|
||||
|
||||
public function read($length): string
|
||||
public function read(int $length): string
|
||||
{
|
||||
if (!\is_int($length)) {
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/psr7',
|
||||
'2.11',
|
||||
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
|
||||
\get_debug_type($length)
|
||||
);
|
||||
if ($length < 0) {
|
||||
throw new \RuntimeException('Length parameter cannot be negative');
|
||||
}
|
||||
|
||||
if ($this->limit === -1) {
|
||||
@@ -176,7 +185,7 @@ final class LimitStream implements StreamInterface
|
||||
|
||||
// Check if the current position is less than the total allowed
|
||||
// bytes + original offset
|
||||
$remaining = ($this->offset + $this->limit) - $this->stream->tell();
|
||||
$remaining = Integers::add($this->offset, $this->limit) - $this->stream->tell();
|
||||
if ($remaining > 0) {
|
||||
// Only return the amount of requested data, ensuring that the byte
|
||||
// limit is not exceeded
|
||||
|
||||
Reference in New Issue
Block a user