Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Stream
File: Append.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
/**
[10] Fix | Delete
* Append stream.
[11] Fix | Delete
*/
[12] Fix | Delete
class MWP_Stream_Append implements MWP_Stream_Interface
[13] Fix | Delete
{
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* @var MWP_Stream_Interface[]
[17] Fix | Delete
*/
[18] Fix | Delete
private $streams = array();
[19] Fix | Delete
[20] Fix | Delete
private $current = 0;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Add a stream to the AppendStream
[24] Fix | Delete
*
[25] Fix | Delete
* @param MWP_Stream_Interface $stream Stream to append. Must be readable.
[26] Fix | Delete
*/
[27] Fix | Delete
public function addStream(MWP_Stream_Interface $stream)
[28] Fix | Delete
{
[29] Fix | Delete
$this->streams[] = $stream;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* @return bool
[34] Fix | Delete
*/
[35] Fix | Delete
public function isSeekable()
[36] Fix | Delete
{
[37] Fix | Delete
return false;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* {@inheritdoc}
[42] Fix | Delete
*/
[43] Fix | Delete
public function seek($offset, $whence = SEEK_SET)
[44] Fix | Delete
{
[45] Fix | Delete
return false;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* {@inheritdoc}
[50] Fix | Delete
*/
[51] Fix | Delete
public function eof()
[52] Fix | Delete
{
[53] Fix | Delete
return $this->isAtLastStream() && $this->getCurrentStream()->eof();
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* {@inheritdoc}
[58] Fix | Delete
*/
[59] Fix | Delete
public function read($length)
[60] Fix | Delete
{
[61] Fix | Delete
$data = '';
[62] Fix | Delete
[63] Fix | Delete
while (!$this->eof()) {
[64] Fix | Delete
while ($this->getCurrentStream()->eof() && !$this->eof()) {
[65] Fix | Delete
$this->moveToNextStream();
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
$currentStreamData = $this->getCurrentStream()->read($length);
[69] Fix | Delete
$data .= $currentStreamData;
[70] Fix | Delete
$length -= strlen($currentStreamData);
[71] Fix | Delete
[72] Fix | Delete
if ($length <= 0) {
[73] Fix | Delete
break;
[74] Fix | Delete
}
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
return $data;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* {@inheritdoc}
[82] Fix | Delete
*/
[83] Fix | Delete
public function close()
[84] Fix | Delete
{
[85] Fix | Delete
foreach ($this->streams as $stream) {
[86] Fix | Delete
$stream->close();
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Tell is not supported.
[92] Fix | Delete
*/
[93] Fix | Delete
public function tell()
[94] Fix | Delete
{
[95] Fix | Delete
return false;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
public function __toString()
[99] Fix | Delete
{
[100] Fix | Delete
$buffer = '';
[101] Fix | Delete
[102] Fix | Delete
while (!$this->eof()) {
[103] Fix | Delete
$buffer .= $this->read(1048576);
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
return $buffer;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
private function moveToNextStream()
[110] Fix | Delete
{
[111] Fix | Delete
if ($this->current >= count($this->streams)) {
[112] Fix | Delete
return false;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$this->current++;
[116] Fix | Delete
[117] Fix | Delete
return true;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
private function isAtLastStream()
[121] Fix | Delete
{
[122] Fix | Delete
return $this->current === count($this->streams) - 1;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
private function getCurrentStream()
[126] Fix | Delete
{
[127] Fix | Delete
return $this->streams[$this->current];
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function