<?php
namespace ModulesAbstract\PluginReports\Report\Model\Gatherer; abstract class GathererAbstract { protected $filters = null; protected $filtersSetManually = []; protected $initialized = false; protected $stats = []; protected $options = []; protected $logger = null; abstract public function getRequiredFilters(); abstract public function getAcceptedFilters(); abstract protected function objectInitialize(); abstract protected function objectDestroy(); abstract protected function objectNext(); public function getInternalStats() { return $this->stats; } public function initialize() { $this->initialized = true; $this->logger = ($this->logger?:new \Engine\Logger\Dummy()); $this->objectInitialize(); } public function destroy() { $this->initialized = false; $this->objectDestroy(); } public function getLogger() { return $this->logger; } public function setLogger($logger) { $this->logger = $logger; return $this; } public function next() { $t1 = microtime(true); if (!$this->initialized) { $this->initialized = true; $this->initialize(); } $ret = null; do { $ret = $this->objectNext(); $this->stats['next:raw']++; } while($ret === "intern:skip"); $this->stats['next:filtered']++; $this->stats['next:time']+= microtime(true)-$t1; if ($ret===null) { $this->destroy(); $this->initialized = false; } return $ret; } public function asIterator() { while ($row = $this->next()) { yield $row; } } public function asArray() { $ret = []; while ($row = $this->next()) { $ret[]= $row; } return $ret; } public function addFilter($key, $value) { $this->filters[$key] = $value; $this->filtersSetManually[$key] = true; return $this; } public function hasFilterSetManually($key) { return isset($this->filtersSetManually[$key]); } public function resetFilters() { $this->filters = []; return $this; } public function setOption($key, $value) { $this->options[$key] = $value; return $this; } public function getOption($key) { return $this->options[$key]; } } 