vendor/sulu/sulu/src/Sulu/Component/DocumentManager/Collection/ChildrenCollection.php line 24

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. use PHPCR\NodeInterface;
  12. use Sulu\Component\DocumentManager\Event\HydrateEvent;
  13. use Sulu\Component\DocumentManager\Events;
  14. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  15. /**
  16.  * Lazily hydrate query results.
  17.  *
  18.  * TODO: Performance -- try fetch depth like in teh PHPCR-ODM ChildrenCollection
  19.  */
  20. class ChildrenCollection extends AbstractLazyCollection
  21. {
  22.     /**
  23.      * @var EventDispatcherInterface
  24.      */
  25.     private $dispatcher;
  26.     /**
  27.      * @var NodeInterface
  28.      */
  29.     private $parentNode;
  30.     /**
  31.      * @var string
  32.      */
  33.     private $locale;
  34.     /**
  35.      * @var array
  36.      */
  37.     private $options;
  38.     /**
  39.      * @var bool
  40.      */
  41.     private $initialized false;
  42.     /**
  43.      * @param string $locale
  44.      * @param array $options
  45.      */
  46.     public function __construct(
  47.         NodeInterface $parentNode,
  48.         EventDispatcherInterface $dispatcher,
  49.         $locale,
  50.         $options = []
  51.     ) {
  52.         $this->parentNode $parentNode;
  53.         $this->dispatcher $dispatcher;
  54.         $this->locale $locale;
  55.         $this->options $options;
  56.     }
  57.     public function current()
  58.     {
  59.         $this->initialize();
  60.         $childNode $this->documents->current();
  61.         $hydrateEvent = new HydrateEvent($childNode$this->locale$this->options);
  62.         $this->dispatcher->dispatch($hydrateEventEvents::HYDRATE);
  63.         return $hydrateEvent->getDocument();
  64.     }
  65.     protected function initialize()
  66.     {
  67.         if (true === $this->initialized) {
  68.             return;
  69.         }
  70.         $this->documents $this->parentNode->getNodes();
  71.         $this->initialized true;
  72.     }
  73. }