vendor/sulu/sulu/src/Sulu/Bundle/ActivityBundle/Application/Subscriber/DispatchSpecificDomainEventSubscriber.php line 38

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\Bundle\ActivityBundle\Application\Subscriber;
  11. use Sulu\Bundle\ActivityBundle\Domain\Event\DomainEvent;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  14. class DispatchSpecificDomainEventSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var EventDispatcherInterface
  18.      */
  19.     private $eventDispatcher;
  20.     public function __construct(
  21.         EventDispatcherInterface $eventDispatcher
  22.     ) {
  23.         $this->eventDispatcher $eventDispatcher;
  24.     }
  25.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             DomainEvent::class => ['dispatchDomainEventWithSpecificEventName'0],
  29.         ];
  30.     }
  31.     public function dispatchDomainEventWithSpecificEventName(DomainEvent $event): void
  32.     {
  33.         // the DomainEventDispatcher service uses DomainEvent::class as event-name when dispatching events. this
  34.         // allows to register listeners that listen to all domain events.
  35.         // this subscriber additionally dispatches the event with a specific event-name such as TagRemovedEvent::class
  36.         // to allow for registering listeners for a specific type of event.
  37.         $this->eventDispatcher->dispatch($event);
  38.     }
  39. }