<?phpnamespace Elements\Bundle\OmnisearchBundle\Service;abstract class AbstractSource implements SourceInterface{ /** * @var Context */ protected $context; /** * @var string */ protected $query; /** * @var \ArrayIterator */ protected $resultList; /** * @var int */ protected $resultCount; /** * duration time in seconds * @var float */ protected $duration = 0; /** * @var int */ protected $limit = 10; /** * @var int */ protected $offset = 0; /** * ASource constructor. */ public function __construct() { $this->reset(); } /** * @param string $query * * @return $this */ public function setQuery($query) { $this->query = $query; return $this; } /** * @return string */ public function getQuery() { return $this->query; } /** * @return int */ public function getOffset() { return $this->offset; } /** * @param int $offset * * @return $this */ public function setOffset($offset) { $this->offset = (int)$offset; return $this; } /** * @return int */ public function getLimit() { return $this->limit; } /** * @param int $limit * * @return $this */ public function setLimit($limit) { $this->limit = (int)$limit; return $this; } /** * @return Context */ public function getContext() { return $this->context; } /** * @param Context $context * * @return $this */ public function setContext(Context $context) { $this->context = $context; return $this; } /** * @return $this */ public function prepare() { return $this; } /** * @return $this */ public function process() { return $this; } /** * @return $this */ public function getResult() { return $this->prepare()->execute()->process(); } /** * @return $this */ public function reset() { $this->resultList = new \ArrayIterator(); return $this; } /** * @return bool */ public function isDirectHit(): bool { $wordCount = str_word_count($this->getQuery(), null, 'äüöÄÜÖ0123456789'); return $wordCount === 1 && $this->resultCount === 1; } /** * @return float */ public function getDuration() { return $this->duration; } /** * @inheritdoc */ public function current() { return $this->resultList->current(); } /** * @inheritdoc */ public function next() { $this->resultList->next(); } /** * @inheritdoc */ public function key() { return $this->resultList->key(); } /** * @inheritdoc */ public function valid() { return $this->resultList->valid(); } /** * @inheritdoc */ public function rewind() { $this->resultList->rewind(); } /** * @inheritdoc */ public function count() { return $this->resultCount; }}