vendor/sulu/sulu/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Mapping/ChildrenSubscriber.php line 51

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\Subscriber\Behavior\Mapping;
  11. use Sulu\Component\DocumentManager\Behavior\Mapping\ChildrenBehavior;
  12. use Sulu\Component\DocumentManager\Event\HydrateEvent;
  13. use Sulu\Component\DocumentManager\Events;
  14. use Sulu\Component\DocumentManager\ProxyFactory;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17.  * Set the children on the document.
  18.  */
  19. class ChildrenSubscriber implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var ProxyFactory
  23.      */
  24.     private $proxyFactory;
  25.     public function __construct(ProxyFactory $proxyFactory)
  26.     {
  27.         $this->proxyFactory $proxyFactory;
  28.     }
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             Events::HYDRATE => 'handleHydrate',
  33.         ];
  34.     }
  35.     public function handleHydrate(HydrateEvent $event)
  36.     {
  37.         $document $event->getDocument();
  38.         if (!$document instanceof ChildrenBehavior) {
  39.             return;
  40.         }
  41.         $accessor $event->getAccessor();
  42.         $accessor->set('children'$this->proxyFactory->createChildrenCollection($document$event->getOptions()));
  43.     }
  44. }