Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Stream
File: Stream.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Stream_Stream implements MWP_Stream_Interface
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var resource
[14] Fix | Delete
*/
[15] Fix | Delete
private $stream;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @var bool
[19] Fix | Delete
*/
[20] Fix | Delete
private $seekable;
[21] Fix | Delete
[22] Fix | Delete
public function __construct($stream)
[23] Fix | Delete
{
[24] Fix | Delete
if (!is_resource($stream)) {
[25] Fix | Delete
throw new InvalidArgumentException('Stream must be a resource');
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
$this->stream = $stream;
[29] Fix | Delete
[30] Fix | Delete
$meta = stream_get_meta_data($this->stream);
[31] Fix | Delete
$this->seekable = $meta['seekable'];
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Returns true if the stream is at the end of the stream.
[36] Fix | Delete
*
[37] Fix | Delete
* @return bool
[38] Fix | Delete
*/
[39] Fix | Delete
public function eof()
[40] Fix | Delete
{
[41] Fix | Delete
return !$this->stream || feof($this->stream);
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Read data from the stream
[46] Fix | Delete
*
[47] Fix | Delete
* @param int $length Read up to $length bytes from the object and return
[48] Fix | Delete
* them. Fewer than $length bytes may be returned if
[49] Fix | Delete
* underlying stream call returns fewer bytes.
[50] Fix | Delete
*
[51] Fix | Delete
* @return string Returns the data read from the stream.
[52] Fix | Delete
*/
[53] Fix | Delete
public function read($length)
[54] Fix | Delete
{
[55] Fix | Delete
return fread($this->stream, $length);
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
public static function factory($resource)
[59] Fix | Delete
{
[60] Fix | Delete
$type = gettype($resource);
[61] Fix | Delete
[62] Fix | Delete
if ($type == 'string') {
[63] Fix | Delete
$stream = fopen('php://temp', 'r+');
[64] Fix | Delete
if ($resource !== '') {
[65] Fix | Delete
fwrite($stream, $resource);
[66] Fix | Delete
fseek($stream, 0);
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
return new self($stream);
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
if ($type == 'resource') {
[73] Fix | Delete
return new self($resource);
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
if ($resource instanceof MWP_Stream_Interface) {
[77] Fix | Delete
return $resource;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
throw new InvalidArgumentException('Invalid resource type: '.$type);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* {@inheritdoc}
[85] Fix | Delete
*/
[86] Fix | Delete
public function isSeekable()
[87] Fix | Delete
{
[88] Fix | Delete
return $this->seekable;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* {@inheritdoc}
[93] Fix | Delete
*/
[94] Fix | Delete
public function seek($offset, $whence = SEEK_SET)
[95] Fix | Delete
{
[96] Fix | Delete
return $this->seekable
[97] Fix | Delete
? fseek($this->stream, $offset, $whence) === 0
[98] Fix | Delete
: false;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* {@inheritdoc}
[103] Fix | Delete
*/
[104] Fix | Delete
public function close()
[105] Fix | Delete
{
[106] Fix | Delete
if ($this->stream !== null) {
[107] Fix | Delete
fclose($this->stream);
[108] Fix | Delete
$this->stream = null;
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* {@inheritdoc}
[114] Fix | Delete
*/
[115] Fix | Delete
public function tell()
[116] Fix | Delete
{
[117] Fix | Delete
return $this->stream !== null ? ftell($this->stream) : false;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
public function __toString()
[121] Fix | Delete
{
[122] Fix | Delete
$buffer = '';
[123] Fix | Delete
[124] Fix | Delete
while (!$this->eof()) {
[125] Fix | Delete
$buffer .= $this->read(1048576);
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
return $buffer;
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function