Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Stream
File: Callable.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_Callable implements MWP_Stream_Interface
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/** @var callable */
[13] Fix | Delete
private $source;
[14] Fix | Delete
[15] Fix | Delete
/** @var int */
[16] Fix | Delete
private $tellPos = 0;
[17] Fix | Delete
[18] Fix | Delete
/** @var MWP_Stream_Buffer */
[19] Fix | Delete
private $buffer;
[20] Fix | Delete
[21] Fix | Delete
/** @var array */
[22] Fix | Delete
private $arguments;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* @param callable $source Source of the stream data. The callable MAY
[26] Fix | Delete
* accept an integer argument used to control the
[27] Fix | Delete
* amount of data to return. The callable MUST
[28] Fix | Delete
* return a string when called, or false on error
[29] Fix | Delete
* or EOF.
[30] Fix | Delete
* @param array $arguments
[31] Fix | Delete
*/
[32] Fix | Delete
public function __construct($source, array $arguments = array())
[33] Fix | Delete
{
[34] Fix | Delete
$this->source = $source;
[35] Fix | Delete
$this->buffer = new MWP_Stream_Buffer();
[36] Fix | Delete
$this->arguments = $arguments;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function close()
[40] Fix | Delete
{
[41] Fix | Delete
$this->tellPos = false;
[42] Fix | Delete
$this->source = null;
[43] Fix | Delete
$this->arguments = array();
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
public function tell()
[47] Fix | Delete
{
[48] Fix | Delete
return $this->tellPos;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
public function eof()
[52] Fix | Delete
{
[53] Fix | Delete
if ($this->source !== null) {
[54] Fix | Delete
return false;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
if ($this->source === null && $this->buffer !== null) {
[58] Fix | Delete
return $this->buffer->eof();
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
return true;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
public function isSeekable()
[65] Fix | Delete
{
[66] Fix | Delete
return false;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
public function seek($offset, $whence = SEEK_SET)
[70] Fix | Delete
{
[71] Fix | Delete
return false;
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
public function read($length)
[75] Fix | Delete
{
[76] Fix | Delete
$data = $this->buffer->read($length);
[77] Fix | Delete
$readLen = strlen($data);
[78] Fix | Delete
$this->tellPos += $readLen;
[79] Fix | Delete
$remaining = $length - $readLen;
[80] Fix | Delete
[81] Fix | Delete
if ($remaining) {
[82] Fix | Delete
$this->pump($remaining);
[83] Fix | Delete
$data .= $this->buffer->read($remaining);
[84] Fix | Delete
$this->tellPos += strlen($data) - $readLen;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
return $data;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
public function __toString()
[91] Fix | Delete
{
[92] Fix | Delete
$buffer = '';
[93] Fix | Delete
[94] Fix | Delete
while (!$this->eof()) {
[95] Fix | Delete
$buffer .= $this->read(1048576);
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
return $buffer;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
private function pump($length)
[102] Fix | Delete
{
[103] Fix | Delete
if ($this->source) {
[104] Fix | Delete
do {
[105] Fix | Delete
$data = call_user_func_array($this->source, array_merge(array($length), $this->arguments));
[106] Fix | Delete
if ($data === false || $data === null) {
[107] Fix | Delete
$this->source = null;
[108] Fix | Delete
[109] Fix | Delete
return;
[110] Fix | Delete
}
[111] Fix | Delete
if ($data instanceof MWP_Stream_Interface) {
[112] Fix | Delete
$this->source = null;
[113] Fix | Delete
$this->buffer = $data;
[114] Fix | Delete
[115] Fix | Delete
return;
[116] Fix | Delete
}
[117] Fix | Delete
$this->buffer->write($data);
[118] Fix | Delete
$length -= strlen($data);
[119] Fix | Delete
} while ($length > 0);
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function