Commit 9dc95366 authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

add convenience methods to JobResult

parent fd857920
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -19,6 +19,31 @@ class JobResult
        }
    }

    public function getDocuments(): \Iterator
    {
        foreach($this->getFiles() as $file) {
            if (!in_array($file->getFileName(), ['out.log', 'job.json'])) {
                yield $file;
            }
        }
    }

    public function getLog(): \Iterator
    {
        foreach ($this->getFiles() as $file){
            if($file->getFileName() == 'out.log'){
                $content = file_get_contents((string)$file);
                $lines = explode(PHP_EOL, $content);
                foreach ($lines as $line){
                    $entry = json_decode($line, true);
                    if($entry){
                        yield $entry;
                    }
                }
            }
        }
    }

    public function __destruct()
    {
        @\unlink($this->result_file_path);