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: AppendStream.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
* Reads from multiple streams, one after the other.
[7] Fix | Delete
*
[8] Fix | Delete
* This is a read-only stream decorator.
[9] Fix | Delete
*/
[10] Fix | Delete
final class AppendStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[11] Fix | Delete
{
[12] Fix | Delete
/** @var StreamInterface[] Streams being decorated */
[13] Fix | Delete
private $streams = [];
[14] Fix | Delete
/** @var bool */
[15] Fix | Delete
private $seekable = \true;
[16] Fix | Delete
/** @var int */
[17] Fix | Delete
private $current = 0;
[18] Fix | Delete
/** @var int */
[19] Fix | Delete
private $pos = 0;
[20] Fix | Delete
/**
[21] Fix | Delete
* @param StreamInterface[] $streams Streams to decorate. Each stream must
[22] Fix | Delete
* be readable.
[23] Fix | Delete
*/
[24] Fix | Delete
public function __construct(array $streams = [])
[25] Fix | Delete
{
[26] Fix | Delete
foreach ($streams as $stream) {
[27] Fix | Delete
$this->addStream($stream);
[28] Fix | Delete
}
[29] Fix | Delete
}
[30] Fix | Delete
public function __toString() : string
[31] Fix | Delete
{
[32] Fix | Delete
try {
[33] Fix | Delete
$this->rewind();
[34] Fix | Delete
return $this->getContents();
[35] Fix | Delete
} catch (\Throwable $e) {
[36] Fix | Delete
if (\PHP_VERSION_ID >= 70400) {
[37] Fix | Delete
throw $e;
[38] Fix | Delete
}
[39] Fix | Delete
\trigger_error(\sprintf('%s::__toString exception: %s', self::class, (string) $e), \E_USER_ERROR);
[40] Fix | Delete
return '';
[41] Fix | Delete
}
[42] Fix | Delete
}
[43] Fix | Delete
/**
[44] Fix | Delete
* Add a stream to the AppendStream
[45] Fix | Delete
*
[46] Fix | Delete
* @param StreamInterface $stream Stream to append. Must be readable.
[47] Fix | Delete
*
[48] Fix | Delete
* @throws \InvalidArgumentException if the stream is not readable
[49] Fix | Delete
*/
[50] Fix | Delete
public function addStream(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream) : void
[51] Fix | Delete
{
[52] Fix | Delete
if (!$stream->isReadable()) {
[53] Fix | Delete
throw new \InvalidArgumentException('Each stream must be readable');
[54] Fix | Delete
}
[55] Fix | Delete
// The stream is only seekable if all streams are seekable
[56] Fix | Delete
if (!$stream->isSeekable()) {
[57] Fix | Delete
$this->seekable = \false;
[58] Fix | Delete
}
[59] Fix | Delete
$this->streams[] = $stream;
[60] Fix | Delete
}
[61] Fix | Delete
public function getContents() : string
[62] Fix | Delete
{
[63] Fix | Delete
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToString($this);
[64] Fix | Delete
}
[65] Fix | Delete
/**
[66] Fix | Delete
* Closes each attached stream.
[67] Fix | Delete
*/
[68] Fix | Delete
public function close() : void
[69] Fix | Delete
{
[70] Fix | Delete
$this->pos = $this->current = 0;
[71] Fix | Delete
$this->seekable = \true;
[72] Fix | Delete
foreach ($this->streams as $stream) {
[73] Fix | Delete
$stream->close();
[74] Fix | Delete
}
[75] Fix | Delete
$this->streams = [];
[76] Fix | Delete
}
[77] Fix | Delete
/**
[78] Fix | Delete
* Detaches each attached stream.
[79] Fix | Delete
*
[80] Fix | Delete
* Returns null as it's not clear which underlying stream resource to return.
[81] Fix | Delete
*/
[82] Fix | Delete
public function detach()
[83] Fix | Delete
{
[84] Fix | Delete
$this->pos = $this->current = 0;
[85] Fix | Delete
$this->seekable = \true;
[86] Fix | Delete
foreach ($this->streams as $stream) {
[87] Fix | Delete
$stream->detach();
[88] Fix | Delete
}
[89] Fix | Delete
$this->streams = [];
[90] Fix | Delete
return null;
[91] Fix | Delete
}
[92] Fix | Delete
public function tell() : int
[93] Fix | Delete
{
[94] Fix | Delete
return $this->pos;
[95] Fix | Delete
}
[96] Fix | Delete
/**
[97] Fix | Delete
* Tries to calculate the size by adding the size of each stream.
[98] Fix | Delete
*
[99] Fix | Delete
* If any of the streams do not return a valid number, then the size of the
[100] Fix | Delete
* append stream cannot be determined and null is returned.
[101] Fix | Delete
*/
[102] Fix | Delete
public function getSize() : ?int
[103] Fix | Delete
{
[104] Fix | Delete
$size = 0;
[105] Fix | Delete
foreach ($this->streams as $stream) {
[106] Fix | Delete
$s = $stream->getSize();
[107] Fix | Delete
if ($s === null) {
[108] Fix | Delete
return null;
[109] Fix | Delete
}
[110] Fix | Delete
$size += $s;
[111] Fix | Delete
}
[112] Fix | Delete
return $size;
[113] Fix | Delete
}
[114] Fix | Delete
public function eof() : bool
[115] Fix | Delete
{
[116] Fix | Delete
return !$this->streams || $this->current >= \count($this->streams) - 1 && $this->streams[$this->current]->eof();
[117] Fix | Delete
}
[118] Fix | Delete
public function rewind() : void
[119] Fix | Delete
{
[120] Fix | Delete
$this->seek(0);
[121] Fix | Delete
}
[122] Fix | Delete
/**
[123] Fix | Delete
* Attempts to seek to the given position. Only supports SEEK_SET.
[124] Fix | Delete
*/
[125] Fix | Delete
public function seek($offset, $whence = \SEEK_SET) : void
[126] Fix | Delete
{
[127] Fix | Delete
if (!$this->seekable) {
[128] Fix | Delete
throw new \RuntimeException('This AppendStream is not seekable');
[129] Fix | Delete
} elseif ($whence !== \SEEK_SET) {
[130] Fix | Delete
throw new \RuntimeException('The AppendStream can only seek with SEEK_SET');
[131] Fix | Delete
}
[132] Fix | Delete
$this->pos = $this->current = 0;
[133] Fix | Delete
// Rewind each stream
[134] Fix | Delete
foreach ($this->streams as $i => $stream) {
[135] Fix | Delete
try {
[136] Fix | Delete
$stream->rewind();
[137] Fix | Delete
} catch (\Exception $e) {
[138] Fix | Delete
throw new \RuntimeException('Unable to seek stream ' . $i . ' of the AppendStream', 0, $e);
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
// Seek to the actual position by reading from each stream
[142] Fix | Delete
while ($this->pos < $offset && !$this->eof()) {
[143] Fix | Delete
$result = $this->read(\min(8096, $offset - $this->pos));
[144] Fix | Delete
if ($result === '') {
[145] Fix | Delete
break;
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
/**
[150] Fix | Delete
* Reads from all of the appended streams until the length is met or EOF.
[151] Fix | Delete
*/
[152] Fix | Delete
public function read($length) : string
[153] Fix | Delete
{
[154] Fix | Delete
$buffer = '';
[155] Fix | Delete
$total = \count($this->streams) - 1;
[156] Fix | Delete
$remaining = $length;
[157] Fix | Delete
$progressToNext = \false;
[158] Fix | Delete
while ($remaining > 0) {
[159] Fix | Delete
// Progress to the next stream if needed.
[160] Fix | Delete
if ($progressToNext || $this->streams[$this->current]->eof()) {
[161] Fix | Delete
$progressToNext = \false;
[162] Fix | Delete
if ($this->current === $total) {
[163] Fix | Delete
break;
[164] Fix | Delete
}
[165] Fix | Delete
++$this->current;
[166] Fix | Delete
}
[167] Fix | Delete
$result = $this->streams[$this->current]->read($remaining);
[168] Fix | Delete
if ($result === '') {
[169] Fix | Delete
$progressToNext = \true;
[170] Fix | Delete
continue;
[171] Fix | Delete
}
[172] Fix | Delete
$buffer .= $result;
[173] Fix | Delete
$remaining = $length - \strlen($buffer);
[174] Fix | Delete
}
[175] Fix | Delete
$this->pos += \strlen($buffer);
[176] Fix | Delete
return $buffer;
[177] Fix | Delete
}
[178] Fix | Delete
public function isReadable() : bool
[179] Fix | Delete
{
[180] Fix | Delete
return \true;
[181] Fix | Delete
}
[182] Fix | Delete
public function isWritable() : bool
[183] Fix | Delete
{
[184] Fix | Delete
return \false;
[185] Fix | Delete
}
[186] Fix | Delete
public function isSeekable() : bool
[187] Fix | Delete
{
[188] Fix | Delete
return $this->seekable;
[189] Fix | Delete
}
[190] Fix | Delete
public function write($string) : int
[191] Fix | Delete
{
[192] Fix | Delete
throw new \RuntimeException('Cannot write to an AppendStream');
[193] Fix | Delete
}
[194] Fix | Delete
/**
[195] Fix | Delete
* @return mixed
[196] Fix | Delete
*/
[197] Fix | Delete
public function getMetadata($key = null)
[198] Fix | Delete
{
[199] Fix | Delete
return $key ? null : [];
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function