<?php
namespace ModulesAbstract\PluginReports\Report\Model\Gatherer; abstract class GathererAbstract { protected $filters = null; protected $initialized = false; protected $stats = []; protected $options = []; abstract public function getRequiredFilters(); 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->objectInitialize(); } public function destroy() { $this->initialized = false; $this->objectDestroy(); } 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; return $this; } 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]; } } 