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

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.     public function seek($position)
  51.     {
  52.         $this->position $position;
  53.         if (!$this->valid()) {
  54.             throw new OutOfBoundsException("invalid seek position ($position)");
  55.         }
  56.     }
  57.     /**
  58.      * @return integer
  59.      */
  60.     public function count()
  61.     {
  62.         return count($this->rows);
  63.     }
  64.     public function rewind()
  65.     {
  66.         $this->position 0;
  67.     }
  68.     public function current()
  69.     {
  70.         if (!$this->valid()) {
  71.             return null;
  72.         }
  73.         return $this->factory->get(Row::class, [$this->objectManager$this->rows[$this->position]]);
  74.     }
  75.     public function key()
  76.     {
  77.         return $this->position;
  78.     }
  79.     public function next()
  80.     {
  81.         ++$this->position;
  82.     }
  83.     /**
  84.      * @return boolean
  85.      */
  86.     public function valid()
  87.     {
  88.         return isset($this->rows[$this->position]);
  89.     }
  90. }