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: CachingStream.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
* Stream decorator that can cache previously read bytes from a sequentially
[7] Fix | Delete
* read stream.
[8] Fix | Delete
*/
[9] Fix | Delete
final class CachingStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[10] Fix | Delete
{
[11] Fix | Delete
use StreamDecoratorTrait;
[12] Fix | Delete
/** @var StreamInterface Stream being wrapped */
[13] Fix | Delete
private $remoteStream;
[14] Fix | Delete
/** @var int Number of bytes to skip reading due to a write on the buffer */
[15] Fix | Delete
private $skipReadBytes = 0;
[16] Fix | Delete
/**
[17] Fix | Delete
* @var StreamInterface
[18] Fix | Delete
*/
[19] Fix | Delete
private $stream;
[20] Fix | Delete
/**
[21] Fix | Delete
* We will treat the buffer object as the body of the stream
[22] Fix | Delete
*
[23] Fix | Delete
* @param StreamInterface $stream Stream to cache. The cursor is assumed to be at the beginning of the stream.
[24] Fix | Delete
* @param StreamInterface $target Optionally specify where data is cached
[25] Fix | Delete
*/
[26] Fix | Delete
public function __construct(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, \YoastSEO_Vendor\Psr\Http\Message\StreamInterface $target = null)
[27] Fix | Delete
{
[28] Fix | Delete
$this->remoteStream = $stream;
[29] Fix | Delete
$this->stream = $target ?: new \YoastSEO_Vendor\GuzzleHttp\Psr7\Stream(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen('php://temp', 'r+'));
[30] Fix | Delete
}
[31] Fix | Delete
public function getSize() : ?int
[32] Fix | Delete
{
[33] Fix | Delete
$remoteSize = $this->remoteStream->getSize();
[34] Fix | Delete
if (null === $remoteSize) {
[35] Fix | Delete
return null;
[36] Fix | Delete
}
[37] Fix | Delete
return \max($this->stream->getSize(), $remoteSize);
[38] Fix | Delete
}
[39] Fix | Delete
public function rewind() : void
[40] Fix | Delete
{
[41] Fix | Delete
$this->seek(0);
[42] Fix | Delete
}
[43] Fix | Delete
public function seek($offset, $whence = \SEEK_SET) : void
[44] Fix | Delete
{
[45] Fix | Delete
if ($whence === \SEEK_SET) {
[46] Fix | Delete
$byte = $offset;
[47] Fix | Delete
} elseif ($whence === \SEEK_CUR) {
[48] Fix | Delete
$byte = $offset + $this->tell();
[49] Fix | Delete
} elseif ($whence === \SEEK_END) {
[50] Fix | Delete
$size = $this->remoteStream->getSize();
[51] Fix | Delete
if ($size === null) {
[52] Fix | Delete
$size = $this->cacheEntireStream();
[53] Fix | Delete
}
[54] Fix | Delete
$byte = $size + $offset;
[55] Fix | Delete
} else {
[56] Fix | Delete
throw new \InvalidArgumentException('Invalid whence');
[57] Fix | Delete
}
[58] Fix | Delete
$diff = $byte - $this->stream->getSize();
[59] Fix | Delete
if ($diff > 0) {
[60] Fix | Delete
// Read the remoteStream until we have read in at least the amount
[61] Fix | Delete
// of bytes requested, or we reach the end of the file.
[62] Fix | Delete
while ($diff > 0 && !$this->remoteStream->eof()) {
[63] Fix | Delete
$this->read($diff);
[64] Fix | Delete
$diff = $byte - $this->stream->getSize();
[65] Fix | Delete
}
[66] Fix | Delete
} else {
[67] Fix | Delete
// We can just do a normal seek since we've already seen this byte.
[68] Fix | Delete
$this->stream->seek($byte);
[69] Fix | Delete
}
[70] Fix | Delete
}
[71] Fix | Delete
public function read($length) : string
[72] Fix | Delete
{
[73] Fix | Delete
// Perform a regular read on any previously read data from the buffer
[74] Fix | Delete
$data = $this->stream->read($length);
[75] Fix | Delete
$remaining = $length - \strlen($data);
[76] Fix | Delete
// More data was requested so read from the remote stream
[77] Fix | Delete
if ($remaining) {
[78] Fix | Delete
// If data was written to the buffer in a position that would have
[79] Fix | Delete
// been filled from the remote stream, then we must skip bytes on
[80] Fix | Delete
// the remote stream to emulate overwriting bytes from that
[81] Fix | Delete
// position. This mimics the behavior of other PHP stream wrappers.
[82] Fix | Delete
$remoteData = $this->remoteStream->read($remaining + $this->skipReadBytes);
[83] Fix | Delete
if ($this->skipReadBytes) {
[84] Fix | Delete
$len = \strlen($remoteData);
[85] Fix | Delete
$remoteData = \substr($remoteData, $this->skipReadBytes);
[86] Fix | Delete
$this->skipReadBytes = \max(0, $this->skipReadBytes - $len);
[87] Fix | Delete
}
[88] Fix | Delete
$data .= $remoteData;
[89] Fix | Delete
$this->stream->write($remoteData);
[90] Fix | Delete
}
[91] Fix | Delete
return $data;
[92] Fix | Delete
}
[93] Fix | Delete
public function write($string) : int
[94] Fix | Delete
{
[95] Fix | Delete
// When appending to the end of the currently read stream, you'll want
[96] Fix | Delete
// to skip bytes from being read from the remote stream to emulate
[97] Fix | Delete
// other stream wrappers. Basically replacing bytes of data of a fixed
[98] Fix | Delete
// length.
[99] Fix | Delete
$overflow = \strlen($string) + $this->tell() - $this->remoteStream->tell();
[100] Fix | Delete
if ($overflow > 0) {
[101] Fix | Delete
$this->skipReadBytes += $overflow;
[102] Fix | Delete
}
[103] Fix | Delete
return $this->stream->write($string);
[104] Fix | Delete
}
[105] Fix | Delete
public function eof() : bool
[106] Fix | Delete
{
[107] Fix | Delete
return $this->stream->eof() && $this->remoteStream->eof();
[108] Fix | Delete
}
[109] Fix | Delete
/**
[110] Fix | Delete
* Close both the remote stream and buffer stream
[111] Fix | Delete
*/
[112] Fix | Delete
public function close() : void
[113] Fix | Delete
{
[114] Fix | Delete
$this->remoteStream->close();
[115] Fix | Delete
$this->stream->close();
[116] Fix | Delete
}
[117] Fix | Delete
private function cacheEntireStream() : int
[118] Fix | Delete
{
[119] Fix | Delete
$target = new \YoastSEO_Vendor\GuzzleHttp\Psr7\FnStream(['write' => 'strlen']);
[120] Fix | Delete
\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToStream($this, $target);
[121] Fix | Delete
return $this->tell();
[122] Fix | Delete
}
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function