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: Stream.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
* PHP stream implementation.
[7] Fix | Delete
*/
[8] Fix | Delete
class Stream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
[9] Fix | Delete
{
[10] Fix | Delete
/**
[11] Fix | Delete
* @see https://www.php.net/manual/en/function.fopen.php
[12] Fix | Delete
* @see https://www.php.net/manual/en/function.gzopen.php
[13] Fix | Delete
*/
[14] Fix | Delete
private const READABLE_MODES = '/r|a\\+|ab\\+|w\\+|wb\\+|x\\+|xb\\+|c\\+|cb\\+/';
[15] Fix | Delete
private const WRITABLE_MODES = '/a|w|r\\+|rb\\+|rw|x|c/';
[16] Fix | Delete
/** @var resource */
[17] Fix | Delete
private $stream;
[18] Fix | Delete
/** @var int|null */
[19] Fix | Delete
private $size;
[20] Fix | Delete
/** @var bool */
[21] Fix | Delete
private $seekable;
[22] Fix | Delete
/** @var bool */
[23] Fix | Delete
private $readable;
[24] Fix | Delete
/** @var bool */
[25] Fix | Delete
private $writable;
[26] Fix | Delete
/** @var string|null */
[27] Fix | Delete
private $uri;
[28] Fix | Delete
/** @var mixed[] */
[29] Fix | Delete
private $customMetadata;
[30] Fix | Delete
/**
[31] Fix | Delete
* This constructor accepts an associative array of options.
[32] Fix | Delete
*
[33] Fix | Delete
* - size: (int) If a read stream would otherwise have an indeterminate
[34] Fix | Delete
* size, but the size is known due to foreknowledge, then you can
[35] Fix | Delete
* provide that size, in bytes.
[36] Fix | Delete
* - metadata: (array) Any additional metadata to return when the metadata
[37] Fix | Delete
* of the stream is accessed.
[38] Fix | Delete
*
[39] Fix | Delete
* @param resource $stream Stream resource to wrap.
[40] Fix | Delete
* @param array{size?: int, metadata?: array} $options Associative array of options.
[41] Fix | Delete
*
[42] Fix | Delete
* @throws \InvalidArgumentException if the stream is not a stream resource
[43] Fix | Delete
*/
[44] Fix | Delete
public function __construct($stream, array $options = [])
[45] Fix | Delete
{
[46] Fix | Delete
if (!\is_resource($stream)) {
[47] Fix | Delete
throw new \InvalidArgumentException('Stream must be a resource');
[48] Fix | Delete
}
[49] Fix | Delete
if (isset($options['size'])) {
[50] Fix | Delete
$this->size = $options['size'];
[51] Fix | Delete
}
[52] Fix | Delete
$this->customMetadata = $options['metadata'] ?? [];
[53] Fix | Delete
$this->stream = $stream;
[54] Fix | Delete
$meta = \stream_get_meta_data($this->stream);
[55] Fix | Delete
$this->seekable = $meta['seekable'];
[56] Fix | Delete
$this->readable = (bool) \preg_match(self::READABLE_MODES, $meta['mode']);
[57] Fix | Delete
$this->writable = (bool) \preg_match(self::WRITABLE_MODES, $meta['mode']);
[58] Fix | Delete
$this->uri = $this->getMetadata('uri');
[59] Fix | Delete
}
[60] Fix | Delete
/**
[61] Fix | Delete
* Closes the stream when the destructed
[62] Fix | Delete
*/
[63] Fix | Delete
public function __destruct()
[64] Fix | Delete
{
[65] Fix | Delete
$this->close();
[66] Fix | Delete
}
[67] Fix | Delete
public function __toString() : string
[68] Fix | Delete
{
[69] Fix | Delete
try {
[70] Fix | Delete
if ($this->isSeekable()) {
[71] Fix | Delete
$this->seek(0);
[72] Fix | Delete
}
[73] Fix | Delete
return $this->getContents();
[74] Fix | Delete
} catch (\Throwable $e) {
[75] Fix | Delete
if (\PHP_VERSION_ID >= 70400) {
[76] Fix | Delete
throw $e;
[77] Fix | Delete
}
[78] Fix | Delete
\trigger_error(\sprintf('%s::__toString exception: %s', self::class, (string) $e), \E_USER_ERROR);
[79] Fix | Delete
return '';
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
public function getContents() : string
[83] Fix | Delete
{
[84] Fix | Delete
if (!isset($this->stream)) {
[85] Fix | Delete
throw new \RuntimeException('Stream is detached');
[86] Fix | Delete
}
[87] Fix | Delete
if (!$this->readable) {
[88] Fix | Delete
throw new \RuntimeException('Cannot read from non-readable stream');
[89] Fix | Delete
}
[90] Fix | Delete
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryGetContents($this->stream);
[91] Fix | Delete
}
[92] Fix | Delete
public function close() : void
[93] Fix | Delete
{
[94] Fix | Delete
if (isset($this->stream)) {
[95] Fix | Delete
if (\is_resource($this->stream)) {
[96] Fix | Delete
\fclose($this->stream);
[97] Fix | Delete
}
[98] Fix | Delete
$this->detach();
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
public function detach()
[102] Fix | Delete
{
[103] Fix | Delete
if (!isset($this->stream)) {
[104] Fix | Delete
return null;
[105] Fix | Delete
}
[106] Fix | Delete
$result = $this->stream;
[107] Fix | Delete
unset($this->stream);
[108] Fix | Delete
$this->size = $this->uri = null;
[109] Fix | Delete
$this->readable = $this->writable = $this->seekable = \false;
[110] Fix | Delete
return $result;
[111] Fix | Delete
}
[112] Fix | Delete
public function getSize() : ?int
[113] Fix | Delete
{
[114] Fix | Delete
if ($this->size !== null) {
[115] Fix | Delete
return $this->size;
[116] Fix | Delete
}
[117] Fix | Delete
if (!isset($this->stream)) {
[118] Fix | Delete
return null;
[119] Fix | Delete
}
[120] Fix | Delete
// Clear the stat cache if the stream has a URI
[121] Fix | Delete
if ($this->uri) {
[122] Fix | Delete
\clearstatcache(\true, $this->uri);
[123] Fix | Delete
}
[124] Fix | Delete
$stats = \fstat($this->stream);
[125] Fix | Delete
if (\is_array($stats) && isset($stats['size'])) {
[126] Fix | Delete
$this->size = $stats['size'];
[127] Fix | Delete
return $this->size;
[128] Fix | Delete
}
[129] Fix | Delete
return null;
[130] Fix | Delete
}
[131] Fix | Delete
public function isReadable() : bool
[132] Fix | Delete
{
[133] Fix | Delete
return $this->readable;
[134] Fix | Delete
}
[135] Fix | Delete
public function isWritable() : bool
[136] Fix | Delete
{
[137] Fix | Delete
return $this->writable;
[138] Fix | Delete
}
[139] Fix | Delete
public function isSeekable() : bool
[140] Fix | Delete
{
[141] Fix | Delete
return $this->seekable;
[142] Fix | Delete
}
[143] Fix | Delete
public function eof() : bool
[144] Fix | Delete
{
[145] Fix | Delete
if (!isset($this->stream)) {
[146] Fix | Delete
throw new \RuntimeException('Stream is detached');
[147] Fix | Delete
}
[148] Fix | Delete
return \feof($this->stream);
[149] Fix | Delete
}
[150] Fix | Delete
public function tell() : int
[151] Fix | Delete
{
[152] Fix | Delete
if (!isset($this->stream)) {
[153] Fix | Delete
throw new \RuntimeException('Stream is detached');
[154] Fix | Delete
}
[155] Fix | Delete
$result = \ftell($this->stream);
[156] Fix | Delete
if ($result === \false) {
[157] Fix | Delete
throw new \RuntimeException('Unable to determine stream position');
[158] Fix | Delete
}
[159] Fix | Delete
return $result;
[160] Fix | Delete
}
[161] Fix | Delete
public function rewind() : void
[162] Fix | Delete
{
[163] Fix | Delete
$this->seek(0);
[164] Fix | Delete
}
[165] Fix | Delete
public function seek($offset, $whence = \SEEK_SET) : void
[166] Fix | Delete
{
[167] Fix | Delete
$whence = (int) $whence;
[168] Fix | Delete
if (!isset($this->stream)) {
[169] Fix | Delete
throw new \RuntimeException('Stream is detached');
[170] Fix | Delete
}
[171] Fix | Delete
if (!$this->seekable) {
[172] Fix | Delete
throw new \RuntimeException('Stream is not seekable');
[173] Fix | Delete
}
[174] Fix | Delete
if (\fseek($this->stream, $offset, $whence) === -1) {
[175] Fix | Delete
throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, \true));
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
public function read($length) : string
[179] Fix | Delete
{
[180] Fix | Delete
if (!isset($this->stream)) {
[181] Fix | Delete
throw new \RuntimeException('Stream is detached');
[182] Fix | Delete
}
[183] Fix | Delete
if (!$this->readable) {
[184] Fix | Delete
throw new \RuntimeException('Cannot read from non-readable stream');
[185] Fix | Delete
}
[186] Fix | Delete
if ($length < 0) {
[187] Fix | Delete
throw new \RuntimeException('Length parameter cannot be negative');
[188] Fix | Delete
}
[189] Fix | Delete
if (0 === $length) {
[190] Fix | Delete
return '';
[191] Fix | Delete
}
[192] Fix | Delete
try {
[193] Fix | Delete
$string = \fread($this->stream, $length);
[194] Fix | Delete
} catch (\Exception $e) {
[195] Fix | Delete
throw new \RuntimeException('Unable to read from stream', 0, $e);
[196] Fix | Delete
}
[197] Fix | Delete
if (\false === $string) {
[198] Fix | Delete
throw new \RuntimeException('Unable to read from stream');
[199] Fix | Delete
}
[200] Fix | Delete
return $string;
[201] Fix | Delete
}
[202] Fix | Delete
public function write($string) : int
[203] Fix | Delete
{
[204] Fix | Delete
if (!isset($this->stream)) {
[205] Fix | Delete
throw new \RuntimeException('Stream is detached');
[206] Fix | Delete
}
[207] Fix | Delete
if (!$this->writable) {
[208] Fix | Delete
throw new \RuntimeException('Cannot write to a non-writable stream');
[209] Fix | Delete
}
[210] Fix | Delete
// We can't know the size after writing anything
[211] Fix | Delete
$this->size = null;
[212] Fix | Delete
$result = \fwrite($this->stream, $string);
[213] Fix | Delete
if ($result === \false) {
[214] Fix | Delete
throw new \RuntimeException('Unable to write to stream');
[215] Fix | Delete
}
[216] Fix | Delete
return $result;
[217] Fix | Delete
}
[218] Fix | Delete
/**
[219] Fix | Delete
* @return mixed
[220] Fix | Delete
*/
[221] Fix | Delete
public function getMetadata($key = null)
[222] Fix | Delete
{
[223] Fix | Delete
if (!isset($this->stream)) {
[224] Fix | Delete
return $key ? null : [];
[225] Fix | Delete
} elseif (!$key) {
[226] Fix | Delete
return $this->customMetadata + \stream_get_meta_data($this->stream);
[227] Fix | Delete
} elseif (isset($this->customMetadata[$key])) {
[228] Fix | Delete
return $this->customMetadata[$key];
[229] Fix | Delete
}
[230] Fix | Delete
$meta = \stream_get_meta_data($this->stream);
[231] Fix | Delete
return $meta[$key] ?? null;
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function