vendor/doctrine/orm/src/Internal/Hydration/IterableResult.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\ORM\Internal\Hydration;
  4. use Iterator;
  5. use ReturnTypeWillChange;
  6. /**
  7.  * Represents a result structure that can be iterated over, hydrating row-by-row
  8.  * during the iteration. An IterableResult is obtained by AbstractHydrator#iterate().
  9.  *
  10.  * @deprecated
  11.  */
  12. class IterableResult implements Iterator
  13. {
  14.     /** @var AbstractHydrator */
  15.     private $hydrator;
  16.     /** @var bool */
  17.     private $rewinded false;
  18.     /** @var int */
  19.     private $key = -1;
  20.     /** @var mixed[]|null */
  21.     private $current null;
  22.     /** @param AbstractHydrator $hydrator */
  23.     public function __construct($hydrator)
  24.     {
  25.         $this->hydrator $hydrator;
  26.     }
  27.     /**
  28.      * @return void
  29.      *
  30.      * @throws HydrationException
  31.      */
  32.     #[ReturnTypeWillChange]
  33.     public function rewind()
  34.     {
  35.         if ($this->rewinded === true) {
  36.             throw new HydrationException('Can only iterate a Result once.');
  37.         }
  38.         $this->current  $this->next();
  39.         $this->rewinded true;
  40.     }
  41.     /**
  42.      * Gets the next set of results.
  43.      *
  44.      * @return mixed[]|false
  45.      */
  46.     #[ReturnTypeWillChange]
  47.     public function next()
  48.     {
  49.         $this->current $this->hydrator->hydrateRow();
  50.         $this->key++;
  51.         return $this->current;
  52.     }
  53.     /** @return mixed */
  54.     #[ReturnTypeWillChange]
  55.     public function current()
  56.     {
  57.         return $this->current;
  58.     }
  59.     /** @return int */
  60.     #[ReturnTypeWillChange]
  61.     public function key()
  62.     {
  63.         return $this->key;
  64.     }
  65.     /** @return bool */
  66.     #[ReturnTypeWillChange]
  67.     public function valid()
  68.     {
  69.         return $this->current !== false;
  70.     }
  71. }