"Fossies" - the Fresh Open Source Software Archive

Member "grav/vendor/doctrine/collections/lib/Doctrine/Common/Collections/AbstractLazyCollection.php" (8 Jun 2020, 5956 Bytes) of package /linux/www/grav-v1.6.26.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractLazyCollection.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Doctrine\Common\Collections;
    4 
    5 use Closure;
    6 
    7 /**
    8  * Lazy collection that is backed by a concrete collection
    9  *
   10  * @psalm-template TKey of array-key
   11  * @psalm-template T
   12  * @template-implements Collection<TKey,T>
   13  */
   14 abstract class AbstractLazyCollection implements Collection
   15 {
   16     /**
   17      * The backed collection to use
   18      *
   19      * @psalm-var Collection<TKey,T>
   20      * @var Collection
   21      */
   22     protected $collection;
   23 
   24     /** @var bool */
   25     protected $initialized = false;
   26 
   27     /**
   28      * {@inheritDoc}
   29      */
   30     public function count()
   31     {
   32         $this->initialize();
   33 
   34         return $this->collection->count();
   35     }
   36 
   37     /**
   38      * {@inheritDoc}
   39      */
   40     public function add($element)
   41     {
   42         $this->initialize();
   43 
   44         return $this->collection->add($element);
   45     }
   46 
   47     /**
   48      * {@inheritDoc}
   49      */
   50     public function clear()
   51     {
   52         $this->initialize();
   53         $this->collection->clear();
   54     }
   55 
   56     /**
   57      * {@inheritDoc}
   58      */
   59     public function contains($element)
   60     {
   61         $this->initialize();
   62 
   63         return $this->collection->contains($element);
   64     }
   65 
   66     /**
   67      * {@inheritDoc}
   68      */
   69     public function isEmpty()
   70     {
   71         $this->initialize();
   72 
   73         return $this->collection->isEmpty();
   74     }
   75 
   76     /**
   77      * {@inheritDoc}
   78      */
   79     public function remove($key)
   80     {
   81         $this->initialize();
   82 
   83         return $this->collection->remove($key);
   84     }
   85 
   86     /**
   87      * {@inheritDoc}
   88      */
   89     public function removeElement($element)
   90     {
   91         $this->initialize();
   92 
   93         return $this->collection->removeElement($element);
   94     }
   95 
   96     /**
   97      * {@inheritDoc}
   98      */
   99     public function containsKey($key)
  100     {
  101         $this->initialize();
  102 
  103         return $this->collection->containsKey($key);
  104     }
  105 
  106     /**
  107      * {@inheritDoc}
  108      */
  109     public function get($key)
  110     {
  111         $this->initialize();
  112 
  113         return $this->collection->get($key);
  114     }
  115 
  116     /**
  117      * {@inheritDoc}
  118      */
  119     public function getKeys()
  120     {
  121         $this->initialize();
  122 
  123         return $this->collection->getKeys();
  124     }
  125 
  126     /**
  127      * {@inheritDoc}
  128      */
  129     public function getValues()
  130     {
  131         $this->initialize();
  132 
  133         return $this->collection->getValues();
  134     }
  135 
  136     /**
  137      * {@inheritDoc}
  138      */
  139     public function set($key, $value)
  140     {
  141         $this->initialize();
  142         $this->collection->set($key, $value);
  143     }
  144 
  145     /**
  146      * {@inheritDoc}
  147      */
  148     public function toArray()
  149     {
  150         $this->initialize();
  151 
  152         return $this->collection->toArray();
  153     }
  154 
  155     /**
  156      * {@inheritDoc}
  157      */
  158     public function first()
  159     {
  160         $this->initialize();
  161 
  162         return $this->collection->first();
  163     }
  164 
  165     /**
  166      * {@inheritDoc}
  167      */
  168     public function last()
  169     {
  170         $this->initialize();
  171 
  172         return $this->collection->last();
  173     }
  174 
  175     /**
  176      * {@inheritDoc}
  177      */
  178     public function key()
  179     {
  180         $this->initialize();
  181 
  182         return $this->collection->key();
  183     }
  184 
  185     /**
  186      * {@inheritDoc}
  187      */
  188     public function current()
  189     {
  190         $this->initialize();
  191 
  192         return $this->collection->current();
  193     }
  194 
  195     /**
  196      * {@inheritDoc}
  197      */
  198     public function next()
  199     {
  200         $this->initialize();
  201 
  202         return $this->collection->next();
  203     }
  204 
  205     /**
  206      * {@inheritDoc}
  207      */
  208     public function exists(Closure $p)
  209     {
  210         $this->initialize();
  211 
  212         return $this->collection->exists($p);
  213     }
  214 
  215     /**
  216      * {@inheritDoc}
  217      */
  218     public function filter(Closure $p)
  219     {
  220         $this->initialize();
  221 
  222         return $this->collection->filter($p);
  223     }
  224 
  225     /**
  226      * {@inheritDoc}
  227      */
  228     public function forAll(Closure $p)
  229     {
  230         $this->initialize();
  231 
  232         return $this->collection->forAll($p);
  233     }
  234 
  235     /**
  236      * {@inheritDoc}
  237      */
  238     public function map(Closure $func)
  239     {
  240         $this->initialize();
  241 
  242         return $this->collection->map($func);
  243     }
  244 
  245     /**
  246      * {@inheritDoc}
  247      */
  248     public function partition(Closure $p)
  249     {
  250         $this->initialize();
  251 
  252         return $this->collection->partition($p);
  253     }
  254 
  255     /**
  256      * {@inheritDoc}
  257      */
  258     public function indexOf($element)
  259     {
  260         $this->initialize();
  261 
  262         return $this->collection->indexOf($element);
  263     }
  264 
  265     /**
  266      * {@inheritDoc}
  267      */
  268     public function slice($offset, $length = null)
  269     {
  270         $this->initialize();
  271 
  272         return $this->collection->slice($offset, $length);
  273     }
  274 
  275     /**
  276      * {@inheritDoc}
  277      */
  278     public function getIterator()
  279     {
  280         $this->initialize();
  281 
  282         return $this->collection->getIterator();
  283     }
  284 
  285     /**
  286      * {@inheritDoc}
  287      */
  288     public function offsetExists($offset)
  289     {
  290         $this->initialize();
  291 
  292         return $this->collection->offsetExists($offset);
  293     }
  294 
  295     /**
  296      * {@inheritDoc}
  297      */
  298     public function offsetGet($offset)
  299     {
  300         $this->initialize();
  301 
  302         return $this->collection->offsetGet($offset);
  303     }
  304 
  305     /**
  306      * {@inheritDoc}
  307      */
  308     public function offsetSet($offset, $value)
  309     {
  310         $this->initialize();
  311         $this->collection->offsetSet($offset, $value);
  312     }
  313 
  314     /**
  315      * {@inheritDoc}
  316      */
  317     public function offsetUnset($offset)
  318     {
  319         $this->initialize();
  320         $this->collection->offsetUnset($offset);
  321     }
  322 
  323     /**
  324      * Is the lazy collection already initialized?
  325      *
  326      * @return bool
  327      */
  328     public function isInitialized()
  329     {
  330         return $this->initialized;
  331     }
  332 
  333     /**
  334      * Initialize the collection
  335      *
  336      * @return void
  337      */
  338     protected function initialize()
  339     {
  340         if ($this->initialized) {
  341             return;
  342         }
  343 
  344         $this->doInitialize();
  345         $this->initialized = true;
  346     }
  347 
  348     /**
  349      * Do the initialization logic
  350      *
  351      * @return void
  352      */
  353     abstract protected function doInitialize();
  354 }