vendor/sulu/sulu/src/Sulu/Component/DocumentManager/Collection/AbstractLazyCollection.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\DocumentManager\Collection;
  11. /**
  12.  * Lazily hydrate query results.
  13.  */
  14. abstract class AbstractLazyCollection implements \Iterator\Countable
  15. {
  16.     /**
  17.      * @var \Iterator
  18.      */
  19.     protected $documents;
  20.     #[\ReturnTypeWillChange]
  21.     public function count()
  22.     {
  23.         $this->initialize();
  24.         return $this->documents->count();
  25.     }
  26.     abstract public function current();
  27.     public function key()
  28.     {
  29.         $this->initialize();
  30.         return $this->documents->key();
  31.     }
  32.     #[\ReturnTypeWillChange]
  33.     public function next()
  34.     {
  35.         $this->initialize();
  36.         $this->documents->next();
  37.     }
  38.     #[\ReturnTypeWillChange]
  39.     public function rewind()
  40.     {
  41.         $this->initialize();
  42.         $this->documents->rewind();
  43.     }
  44.     #[\ReturnTypeWillChange]
  45.     public function valid()
  46.     {
  47.         $this->initialize();
  48.         return $this->documents->valid();
  49.     }
  50.     /**
  51.      * Returns a array of all documents in the collection.
  52.      *
  53.      * @return array
  54.      */
  55.     public function toArray()
  56.     {
  57.         $copy = [];
  58.         foreach ($this as $document) {
  59.             $copy[] = $document;
  60.         }
  61.         return $copy;
  62.     }
  63.     /**
  64.      * Initialize the collection documents.
  65.      */
  66.     abstract protected function initialize();
  67. }