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

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.     #[\ReturnTypeWillChange]
  27.     abstract public function current();
  28.     #[\ReturnTypeWillChange]
  29.     public function key()
  30.     {
  31.         $this->initialize();
  32.         return $this->documents->key();
  33.     }
  34.     #[\ReturnTypeWillChange]
  35.     public function next()
  36.     {
  37.         $this->initialize();
  38.         $this->documents->next();
  39.     }
  40.     #[\ReturnTypeWillChange]
  41.     public function rewind()
  42.     {
  43.         $this->initialize();
  44.         $this->documents->rewind();
  45.     }
  46.     #[\ReturnTypeWillChange]
  47.     public function valid()
  48.     {
  49.         $this->initialize();
  50.         return $this->documents->valid();
  51.     }
  52.     /**
  53.      * Returns a array of all documents in the collection.
  54.      *
  55.      * @return array
  56.      */
  57.     public function toArray()
  58.     {
  59.         $copy = [];
  60.         foreach ($this as $document) {
  61.             $copy[] = $document;
  62.         }
  63.         return $copy;
  64.     }
  65.     /**
  66.      * Initialize the collection documents.
  67.      */
  68.     abstract protected function initialize();
  69. }