Add DI to ParsedLogIterator, replace constructors with fluent api

This commit is contained in:
fabrixxm 2021-08-19 13:03:45 +02:00
parent a62124285d
commit ec4f53d56f
5 changed files with 88 additions and 27 deletions

View file

@ -36,31 +36,64 @@ class ParsedLogIterator implements \Iterator
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 string $filename File to open
* @param int $limit Max num of lines to read
* @param array $filter filters per column
* @param string $search string to search to filter lines
* @param ReversedFileReader $reader
*/
public function __construct(string $filename, int $limit = 0, array $filters = [], string $search = "")
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
* @return $this
*/
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;
}
/**