3 * @copyright Copyright (C) 2021, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 namespace Friendica\Model\Log;
23 use \Friendica\Util\ReversedFileReader;
24 use \Friendica\Object\Log\ParsedLog;
28 * An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
30 * Uses `\Friendica\Util\ReversedFileReader` to fetch log lines
31 * from newest to oldest
33 class ParsedLogIterator implements \Iterator
35 public function __construct(string $filename, int $limit=0)
37 $this->reader = new ReversedFileReader($filename);
39 $this->_limit = $limit;
42 public function next()
44 $this->reader->next();
45 if ($this->_limit > 0 && $this->reader->key() > $this->_limit) {
49 if ($this->reader->valid()) {
50 $line = $this->reader->current();
51 $this->_value = new ParsedLog($this->reader->key(), $line);
58 public function rewind()
61 $this->reader->rewind();
67 return $this->reader->key();
70 public function current()
75 public function valid()
77 return ! is_null($this->_value);