Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Stream
File: LazyFile.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
* Lazily open file stream for reading and close it when EOF is reached.
[11] Fix | Delete
*/
[12] Fix | Delete
class MWP_Stream_LazyFile 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 $stream = null;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @var mixed
[22] Fix | Delete
*/
[23] Fix | Delete
private $realPath;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @var bool
[27] Fix | Delete
*/
[28] Fix | Delete
private $initialized = false;
[29] Fix | Delete
[30] Fix | Delete
public function __construct($realPath)
[31] Fix | Delete
{
[32] Fix | Delete
$this->realPath = $realPath;
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* {@inheritdoc}
[37] Fix | Delete
*/
[38] Fix | Delete
public function close()
[39] Fix | Delete
{
[40] Fix | Delete
if ($this->stream !== null) {
[41] Fix | Delete
$this->stream->close();
[42] Fix | Delete
}
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* {@inheritdoc}
[47] Fix | Delete
*/
[48] Fix | Delete
public function tell()
[49] Fix | Delete
{
[50] Fix | Delete
if (!$this->initialized) {
[51] Fix | Delete
return 0;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
return $this->stream !== null ? $this->stream->tell() : false;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* {@inheritdoc}
[59] Fix | Delete
*/
[60] Fix | Delete
public function isSeekable()
[61] Fix | Delete
{
[62] Fix | Delete
$this->initialize();
[63] Fix | Delete
[64] Fix | Delete
return $this->stream !== null ? $this->stream->isSeekable() : false;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* {@inheritdoc}
[69] Fix | Delete
*/
[70] Fix | Delete
public function seek($offset, $whence = SEEK_SET)
[71] Fix | Delete
{
[72] Fix | Delete
$this->initialize();
[73] Fix | Delete
[74] Fix | Delete
return $this->stream !== null ? $this->stream->seek($offset, $whence) : false;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* {@inheritdoc}
[79] Fix | Delete
*/
[80] Fix | Delete
public function eof()
[81] Fix | Delete
{
[82] Fix | Delete
$this->initialize();
[83] Fix | Delete
[84] Fix | Delete
return $this->stream !== null ? $this->stream->eof() : true;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* {@inheritdoc}
[89] Fix | Delete
*/
[90] Fix | Delete
public function read($length)
[91] Fix | Delete
{
[92] Fix | Delete
$this->initialize();
[93] Fix | Delete
[94] Fix | Delete
if ($this->stream === null) {
[95] Fix | Delete
return null;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$data = $this->stream->read($length);
[99] Fix | Delete
[100] Fix | Delete
if ($this->eof()) {
[101] Fix | Delete
$this->close();
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
return $data;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
public function __toString()
[108] Fix | Delete
{
[109] Fix | Delete
$buffer = '';
[110] Fix | Delete
[111] Fix | Delete
while (!$this->eof()) {
[112] Fix | Delete
$buffer .= $this->read(1048576);
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return $buffer;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
private function initialize()
[119] Fix | Delete
{
[120] Fix | Delete
if ($this->initialized === false) {
[121] Fix | Delete
if (file_exists($this->realPath)) {
[122] Fix | Delete
$handle = @fopen($this->realPath, "rb");
[123] Fix | Delete
if ($handle !== false) {
[124] Fix | Delete
$this->stream = MWP_Stream_Stream::factory($handle);
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
$this->initialized = true;
[128] Fix | Delete
}
[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