filename = $logfile; } private function readLog(string $filename) { if (!file_exists($filename)) { $this->lastLog = null; $this->log = []; $this->index = null; $this->lindex = null; return; } $log = json_decode(file_get_contents($filename), true); $this->lastLog = $log['lastlog']??null; $this->log = $log['events']; $this->lindex = 0; if ($this->index === null) { $this->index = 0; } } public function rewind(): void { $this->index = null; $this->readLog($this->filename); } public function current() { return $this->log[$this->lindex]; } public function key() { return $this->index; } public function next(): void { $this->index++; $this->lindex++; if ($this->lindex >= count($this->log)) { if ($this->lastLog) { $this->readLog($this->lastLog); } else { $this->lindex = null; } } } public function valid(): bool { return $this->lindex !== null; } }