Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../vendor_p.../guzzleht.../psr7/src
File: LimitStream.php
<?php
[0] Fix | Delete
[1] Fix | Delete
declare (strict_types=1);
[2] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
[3] Fix | Delete
[4] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
[5] Fix | Delete
/**
[6] Fix | Delete
* Decorator used to return only a subset of a stream.
[7] Fix | Delete
*/
[8] Fix | Delete
final class LimitStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[9] Fix | Delete
{
[10] Fix | Delete
use StreamDecoratorTrait;
[11] Fix | Delete
/** @var int Offset to start reading from */
[12] Fix | Delete
private $offset;
[13] Fix | Delete
/** @var int Limit the number of bytes that can be read */
[14] Fix | Delete
private $limit;
[15] Fix | Delete
/** @var StreamInterface */
[16] Fix | Delete
private $stream;
[17] Fix | Delete
/**
[18] Fix | Delete
* @param StreamInterface $stream Stream to wrap
[19] Fix | Delete
* @param int $limit Total number of bytes to allow to be read
[20] Fix | Delete
* from the stream. Pass -1 for no limit.
[21] Fix | Delete
* @param int $offset Position to seek to before reading (only
[22] Fix | Delete
* works on seekable streams).
[23] Fix | Delete
*/
[24] Fix | Delete
public function __construct(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, int $limit = -1, int $offset = 0)
[25] Fix | Delete
{
[26] Fix | Delete
$this->stream = $stream;
[27] Fix | Delete
$this->setLimit($limit);
[28] Fix | Delete
$this->setOffset($offset);
[29] Fix | Delete
}
[30] Fix | Delete
public function eof() : bool
[31] Fix | Delete
{
[32] Fix | Delete
// Always return true if the underlying stream is EOF
[33] Fix | Delete
if ($this->stream->eof()) {
[34] Fix | Delete
return \true;
[35] Fix | Delete
}
[36] Fix | Delete
// No limit and the underlying stream is not at EOF
[37] Fix | Delete
if ($this->limit === -1) {
[38] Fix | Delete
return \false;
[39] Fix | Delete
}
[40] Fix | Delete
return $this->stream->tell() >= $this->offset + $this->limit;
[41] Fix | Delete
}
[42] Fix | Delete
/**
[43] Fix | Delete
* Returns the size of the limited subset of data
[44] Fix | Delete
*/
[45] Fix | Delete
public function getSize() : ?int
[46] Fix | Delete
{
[47] Fix | Delete
if (null === ($length = $this->stream->getSize())) {
[48] Fix | Delete
return null;
[49] Fix | Delete
} elseif ($this->limit === -1) {
[50] Fix | Delete
return $length - $this->offset;
[51] Fix | Delete
} else {
[52] Fix | Delete
return \min($this->limit, $length - $this->offset);
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
/**
[56] Fix | Delete
* Allow for a bounded seek on the read limited stream
[57] Fix | Delete
*/
[58] Fix | Delete
public function seek($offset, $whence = \SEEK_SET) : void
[59] Fix | Delete
{
[60] Fix | Delete
if ($whence !== \SEEK_SET || $offset < 0) {
[61] Fix | Delete
throw new \RuntimeException(\sprintf('Cannot seek to offset %s with whence %s', $offset, $whence));
[62] Fix | Delete
}
[63] Fix | Delete
$offset += $this->offset;
[64] Fix | Delete
if ($this->limit !== -1) {
[65] Fix | Delete
if ($offset > $this->offset + $this->limit) {
[66] Fix | Delete
$offset = $this->offset + $this->limit;
[67] Fix | Delete
}
[68] Fix | Delete
}
[69] Fix | Delete
$this->stream->seek($offset);
[70] Fix | Delete
}
[71] Fix | Delete
/**
[72] Fix | Delete
* Give a relative tell()
[73] Fix | Delete
*/
[74] Fix | Delete
public function tell() : int
[75] Fix | Delete
{
[76] Fix | Delete
return $this->stream->tell() - $this->offset;
[77] Fix | Delete
}
[78] Fix | Delete
/**
[79] Fix | Delete
* Set the offset to start limiting from
[80] Fix | Delete
*
[81] Fix | Delete
* @param int $offset Offset to seek to and begin byte limiting from
[82] Fix | Delete
*
[83] Fix | Delete
* @throws \RuntimeException if the stream cannot be seeked.
[84] Fix | Delete
*/
[85] Fix | Delete
public function setOffset(int $offset) : void
[86] Fix | Delete
{
[87] Fix | Delete
$current = $this->stream->tell();
[88] Fix | Delete
if ($current !== $offset) {
[89] Fix | Delete
// If the stream cannot seek to the offset position, then read to it
[90] Fix | Delete
if ($this->stream->isSeekable()) {
[91] Fix | Delete
$this->stream->seek($offset);
[92] Fix | Delete
} elseif ($current > $offset) {
[93] Fix | Delete
throw new \RuntimeException("Could not seek to stream offset {$offset}");
[94] Fix | Delete
} else {
[95] Fix | Delete
$this->stream->read($offset - $current);
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
$this->offset = $offset;
[99] Fix | Delete
}
[100] Fix | Delete
/**
[101] Fix | Delete
* Set the limit of bytes that the decorator allows to be read from the
[102] Fix | Delete
* stream.
[103] Fix | Delete
*
[104] Fix | Delete
* @param int $limit Number of bytes to allow to be read from the stream.
[105] Fix | Delete
* Use -1 for no limit.
[106] Fix | Delete
*/
[107] Fix | Delete
public function setLimit(int $limit) : void
[108] Fix | Delete
{
[109] Fix | Delete
$this->limit = $limit;
[110] Fix | Delete
}
[111] Fix | Delete
public function read($length) : string
[112] Fix | Delete
{
[113] Fix | Delete
if ($this->limit === -1) {
[114] Fix | Delete
return $this->stream->read($length);
[115] Fix | Delete
}
[116] Fix | Delete
// Check if the current position is less than the total allowed
[117] Fix | Delete
// bytes + original offset
[118] Fix | Delete
$remaining = $this->offset + $this->limit - $this->stream->tell();
[119] Fix | Delete
if ($remaining > 0) {
[120] Fix | Delete
// Only return the amount of requested data, ensuring that the byte
[121] Fix | Delete
// limit is not exceeded
[122] Fix | Delete
return $this->stream->read(\min($remaining, $length));
[123] Fix | Delete
}
[124] Fix | Delete
return '';
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function