return self::$dice->create(Model\Storage\IWritableStorage::class);
}
+ /**
+ * @return Model\Log\ParsedLogIterator
+ */
+ public static function parsedLogIterator()
+ {
+ return self::$dice->create(Model\Log\ParsedLogIterator::class);
+ }
+
//
// "Network" namespace
//
private $reader;
/** @var ParsedLog current iterator value*/
- private $value;
+ private $value = null;
/** @var int max number of lines to read */
- private $limit;
+ private $limit = 0;
/** @var array filters per column */
- private $filters;
+ private $filters = [];
/** @var string search term */
- private $search;
+ private $search = "";
+ /**
+ * @param ReversedFileReader $reader
+ */
+ public function __construct(ReversedFileReader $reader)
+ {
+ $this->reader = $reader;
+ }
+
/**
* @param string $filename File to open
+ * @return $this
+ */
+ public function open(string $filename)
+ {
+ $this->reader->open($filename);
+ return $this;
+ }
+
+ /**
* @param int $limit Max num of lines to read
- * @param array $filter filters per column
- * @param string $search string to search to filter lines
+ * @return $this
*/
- public function __construct(string $filename, int $limit = 0, array $filters = [], string $search = "")
+ public function withLimit(int $limit)
+ {
+ $this->limit = $limit;
+ return $this;
+ }
+
+ /**
+ * @param array $filters filters per column
+ * @return $this
+ */
+ public function withFilters(array $filters)
{
- $this->reader = new ReversedFileReader($filename);
- $this->value = null;
- $this->limit = $limit;
$this->filters = $filters;
- $this->search = $search;
+ return $this;
+ }
+
+ /**
+ * @param string $search string to search to filter lines
+ * @return $this
+ */
+ public function withSearch(string $search)
+ {
+ $this->search = $search;
+ return $this;
}
/**
$error = DI::l10n()->t('Error trying to open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s exist and is readable.', $f);
} else {
try {
- $data = new ParsedLogIterator($f, self::LIMIT, $filters, $search);
+ $data = DI::parsedLogIterator()
+ ->open($f)
+ ->withLimit(self::LIMIT)
+ ->withFilters($filters)
+ ->withSearch($search);
} catch (Exception $e) {
$error = DI::l10n()->t('Couldn\'t open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s is readable.', $f);
}
const BUFFER_SIZE = 4096;
const SEPARATOR = "\n";
+ /** @var resource */
+ private $fh = null;
+
/** @var int */
- private $filesize;
+ private $filesize = -1;
/** @var int */
- private $pos;
+ private $pos = -1;
/** @var array */
- private $buffer;
+ private $buffer = null;
/** @var int */
- private $key;
+ private $key = -1;
/** @var string */
- private $value;
+ private $value = null;
- public function __construct($filename)
+ /**
+ * Open $filename for read and reset iterator
+ *
+ * @param string $filename File to open
+ * @return $this
+ */
+ public function open(string $filename)
{
- $this->_fh = fopen($filename, 'r');
- if (!$this->_fh) {
+ $this->fh = fopen($filename, 'r');
+ if (!$this->fh) {
// this should use a custom exception.
throw \Exception("Unable to open $filename");
}
$this->buffer = null;
$this->key = -1;
$this->value = null;
+ return $this;
}
- public function _read($size)
+ private function _read($size)
{
$this->pos -= $size;
- fseek($this->_fh, $this->pos);
- return fread($this->_fh, $size);
+ fseek($this->fh, $this->pos);
+ return fread($this->fh, $size);
}
- public function _readline()
+ private function _readline()
{
$buffer = & $this->buffer;
while (true) {
use Friendica\Factory;
use Friendica\Model\Storage\IWritableStorage;
use Friendica\Model\User\Cookie;
+use Friendica\Model\Log\ParsedLogIterator;
use Friendica\Network;
use Friendica\Util;
use Psr\Log\LoggerInterface;
$_SERVER
],
],
+ ParsedLogIterator::class => [
+ 'constructParams' => [
+ [Dice::INSTANCE => Util\ReversedFileReader::class],
+ ]
+ ]
];