vendor/shopware/core/Framework/Event/NestedEventDispatcher.php line 68

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Event;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. #[Package('core')]
  7. class NestedEventDispatcher implements EventDispatcherInterface
  8. {
  9.     /**
  10.      * @var EventDispatcherInterface
  11.      */
  12.     private $dispatcher;
  13.     /**
  14.      * @internal
  15.      */
  16.     public function __construct(EventDispatcherInterface $dispatcher)
  17.     {
  18.         $this->dispatcher $dispatcher;
  19.     }
  20.     public function dispatch($event, ?string $eventName null): object
  21.     {
  22.         if ($event instanceof NestedEvent && $events $event->getEvents()) {
  23.             foreach ($events as $nested) {
  24.                 $name null;
  25.                 if ($nested instanceof GenericEvent) {
  26.                     $name $nested->getName();
  27.                 }
  28.                 $this->dispatch($nested$name);
  29.             }
  30.         }
  31.         return $this->dispatcher->dispatch($event$eventName);
  32.     }
  33.     /**
  34.      * @param callable $listener can not use native type declaration @see https://github.com/symfony/symfony/issues/42283
  35.      */
  36.     public function addListener(string $eventName$listenerint $priority 0): void
  37.     {
  38.         $this->dispatcher->addListener($eventName$listener$priority);
  39.     }
  40.     public function addSubscriber(EventSubscriberInterface $subscriber): void
  41.     {
  42.         $this->dispatcher->addSubscriber($subscriber);
  43.     }
  44.     /**
  45.      * @param callable $listener can not use native type hint as it is incompatible with symfony <5.3.4
  46.      */
  47.     public function removeListener(string $eventName$listener): void
  48.     {
  49.         $this->dispatcher->removeListener($eventName$listener);
  50.     }
  51.     public function removeSubscriber(EventSubscriberInterface $subscriber): void
  52.     {
  53.         $this->dispatcher->removeSubscriber($subscriber);
  54.     }
  55.     public function getListeners(?string $eventName null): array
  56.     {
  57.         return $this->dispatcher->getListeners($eventName);
  58.     }
  59.     /**
  60.      * @param callable $listener can not use native type hint as it is incompatible with symfony <5.3.4
  61.      */
  62.     public function getListenerPriority(string $eventName$listener): ?int
  63.     {
  64.         return $this->dispatcher->getListenerPriority($eventName$listener);
  65.     }
  66.     public function hasListeners(?string $eventName null): bool
  67.     {
  68.         return $this->dispatcher->hasListeners($eventName);
  69.     }
  70. }