vendor/elements/omnisearch-bundle/src/Service/ResultList.php line 96

Open in your IDE?
  1. <?php
  2. namespace Elements\Bundle\OmnisearchBundle\Service;
  3. class ResultList implements ResultListInterface
  4. {
  5.     /**
  6.      * @var \ArrayIterator|SourceInterface[]
  7.      */
  8.     protected $sources;
  9.     /**
  10.      * @var float
  11.      */
  12.     protected $duration;
  13.     /**
  14.      * ResultList constructor.
  15.      */
  16.     public function __construct()
  17.     {
  18.         $this->sources = new \ArrayIterator();
  19.     }
  20.     /**
  21.      * @param SourceInterface $source
  22.      * @param string  $reference
  23.      *
  24.      * @return $this
  25.      */
  26.     public function addSource(SourceInterface $sourcestring $reference)
  27.     {
  28.         $this->sources->offsetSet($reference$source);
  29.         return $this;
  30.     }
  31.     /**
  32.      * @param string $reference
  33.      *
  34.      * @return SourceInterface
  35.      */
  36.     public function getSourceByReference(string $reference)
  37.     {
  38.         return $this->sources->offsetGet$reference );
  39.     }
  40.     /**
  41.      * @inheritdoc
  42.      */
  43.     public function current()
  44.     {
  45.         return $this->sources->current();
  46.     }
  47.     /**
  48.      * @inheritdoc
  49.      */
  50.     public function next()
  51.     {
  52.         $this->sources->next();
  53.     }
  54.     /**
  55.      * @inheritdoc
  56.      */
  57.     public function key()
  58.     {
  59.         return $this->sources->key();
  60.     }
  61.     /**
  62.      * @inheritdoc
  63.      */
  64.     public function valid()
  65.     {
  66.         return $this->sources->valid();
  67.     }
  68.     /**
  69.      * @inheritdoc
  70.      */
  71.     public function rewind()
  72.     {
  73.         $this->sources->rewind();
  74.     }
  75.     /**
  76.      * @inheritdoc
  77.      */
  78.     public function count()
  79.     {
  80.         $count 0;
  81.         foreach($this->sources as $source)
  82.         {
  83.             $count += $source->count();
  84.         }
  85.         return $count;
  86.     }
  87.     /**
  88.      * @return float
  89.      */
  90.     public function getDuration()
  91.     {
  92.         return $this->duration;
  93.     }
  94.     /**
  95.      * @param float $duration
  96.      *
  97.      * @return $this
  98.      */
  99.     public function setDuration($duration)
  100.     {
  101.         $this->duration = (float)$duration;
  102.         return $this;
  103.     }
  104.     /**
  105.      * @return float|int
  106.      */
  107.     public function getSourceDuration()
  108.     {
  109.         $duration 0;
  110.         foreach($this->sources as $source)
  111.         {
  112.             $duration += $source->getDuration();
  113.         }
  114.         return $duration;
  115.     }
  116. }