vendor/jackalope/jackalope/src/Jackalope/Query/RowIterator.php line 84

Open in your IDE?
  1. <?php
  2. namespace Jackalope\Query;
  3. use Countable;
  4. use SeekableIterator;
  5. use OutOfBoundsException;
  6. use Jackalope\ObjectManager;
  7. use Jackalope\FactoryInterface;
  8. /**
  9.  * Iterator to efficiently iterate over the raw query result.
  10.  *
  11.  * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  12.  * @license http://opensource.org/licenses/MIT MIT License
  13.  */
  14. class RowIterator implements SeekableIteratorCountable
  15. {
  16.     /**
  17.      * @var ObjectManager
  18.      */
  19.     protected $objectManager;
  20.     /**
  21.      * @var FactoryInterface
  22.      */
  23.     protected $factory;
  24.     /**
  25.      * @var array
  26.      */
  27.     protected $rows;
  28.     /**
  29.      * @var integer
  30.      */
  31.     protected $position 0;
  32.     /**
  33.      * Create the iterator.
  34.      *
  35.      * @param FactoryInterface $factory       the object factory
  36.      * @param ObjectManager    $objectManager
  37.      * @param array            $rows          Raw data as described in QueryResult and \Jackalope\Transport\TransportInterface
  38.      */
  39.     public function __construct(FactoryInterface $factoryObjectManager $objectManager$rows)
  40.     {
  41.         $this->factory $factory;
  42.         $this->objectManager $objectManager;
  43.         $this->rows $rows;
  44.     }
  45.     /**
  46.      * @param int $position
  47.      *
  48.      * @throws OutOfBoundsException
  49.      */
  50.     #[\ReturnTypeWillChange]
  51.     public function seek($position)
  52.     {
  53.         $this->position $position;
  54.         if (!$this->valid()) {
  55.             throw new OutOfBoundsException("invalid seek position ($position)");
  56.         }
  57.     }
  58.     /**
  59.      * @return integer
  60.      */
  61.     #[\ReturnTypeWillChange]
  62.     public function count()
  63.     {
  64.         return count($this->rows);
  65.     }
  66.     #[\ReturnTypeWillChange]
  67.     public function rewind()
  68.     {
  69.         $this->position 0;
  70.     }
  71.     #[\ReturnTypeWillChange]
  72.     public function current()
  73.     {
  74.         if (!$this->valid()) {
  75.             return null;
  76.         }
  77.         return $this->factory->get(Row::class, [$this->objectManager$this->rows[$this->position]]);
  78.     }
  79.     #[\ReturnTypeWillChange]
  80.     public function key()
  81.     {
  82.         return $this->position;
  83.     }
  84.     #[\ReturnTypeWillChange]
  85.     public function next()
  86.     {
  87.         ++$this->position;
  88.     }
  89.     /**
  90.      * @return boolean
  91.      */
  92.     #[\ReturnTypeWillChange]
  93.     public function valid()
  94.     {
  95.         return isset($this->rows[$this->position]);
  96.     }
  97. }