src/EventSubscriber/Composition/CompositionSubscriber.php line 74

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Composition;
  3. use App\Entity\Logs\EventLog;
  4. use App\Event\Composition\CompositionCreatedEvent;
  5. use App\Event\Composition\CompositionDeleteEvent;
  6. use App\Event\Composition\CompositionEditedEvent;
  7. use App\Event\Composition\CompositionPublishedEvent;
  8. use App\Event\Composition\CompositionUnsubmittedEvent;
  9. use App\Event\Composition\CompositionTakedDownEvent;
  10. use App\Event\LogEvent;
  11. use App\Service\AuthenticationService;
  12. use App\Service\Mailer\CompositionMailer;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  16. class CompositionSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var AuthenticationService
  20.      */
  21.     private $authenticationService;
  22.     /**
  23.      * @var EventDispatcherInterface
  24.      */
  25.     private $eventDispatcher;
  26.     /**
  27.      * @var CompositionMailer
  28.      */
  29.     private $compositionMailer;
  30.     public function __construct(
  31.         AuthenticationService $authenticationService,
  32.         EventDispatcherInterface $eventDispatcher,
  33.         CompositionMailer $compositionMailer
  34.     )
  35.     {
  36.         $this->authenticationService $authenticationService;
  37.         $this->eventDispatcher $eventDispatcher;
  38.         $this->compositionMailer $compositionMailer;
  39.     }
  40.     /**
  41.      * @inheritDoc
  42.      */
  43.     public static function getSubscribedEvents(): array
  44.     {
  45.         return [
  46.             CompositionCreatedEvent::class      => 'onCompositionCreatedEvent',
  47.             CompositionUnsubmittedEvent::class  => 'onCompositionUnsubmittedEvent',
  48.             CompositionPublishedEvent::class    => 'onCompositionPublishedEvent',
  49.             CompositionTakedDownEvent::class    => 'onCompositionTakedDownEvent',
  50.             CompositionDeleteEvent::class       => 'onCompositionDeleteEvent',
  51.             CompositionEditedEvent::class       => 'onCompositionEditedEvent'
  52.         ];
  53.     }
  54.     /**
  55.      * @param CompositionCreatedEvent $event
  56.      */
  57.     public function onCompositionCreatedEvent(CompositionCreatedEvent $event): void
  58.     {
  59.         $this->eventDispatcher->dispatch(new LogEvent($event->getComposition(), $this->authenticationService->getUser(), EventLog::TYPE_COMPOSITION_CREATED));
  60.     }
  61.     /**
  62.      * @param CompositionUnsubmittedEvent $event
  63.      * @throws TransportExceptionInterface
  64.      */
  65.     public function onCompositionUnsubmittedEvent(CompositionUnsubmittedEvent $event): void
  66.     {
  67.         $this->compositionMailer->sendCompositionUnsubmittedEmails($event->getComposition());
  68.     }
  69.     /**
  70.      * @param CompositionPublishedEvent $event
  71.      * @throws TransportExceptionInterface
  72.      */
  73.     public function onCompositionPublishedEvent(CompositionPublishedEvent $event): void
  74.     {
  75.         $this->compositionMailer->sendCompositionPublishedEmails($event->getComposition());
  76.     }
  77.     /**
  78.      * @param CompositionTakedDownEvent $event
  79.      * @throws TransportExceptionInterface
  80.      */
  81.     public function onCompositionTakedDownEvent(CompositionTakedDownEvent $event): void
  82.     {
  83.         $this->compositionMailer->sendCompositionTakedDownEmails($event->getComposition());
  84.     }
  85.     /**
  86.      * @param CompositionDeleteEvent $event
  87.      * @throws TransportExceptionInterface
  88.      */
  89.     public function onCompositionDeleteEvent(CompositionDeleteEvent $event): void
  90.     {
  91.         //$this->compositionMailer->sendCompositionDeletemails($event->getComposition());
  92.     }
  93.     /**
  94.      * @param CompositionEditedEvent $event
  95.      * @throws TransportExceptionInterface
  96.      */
  97.     public function onCompositionEditedEvent(CompositionEditedEvent $event): void
  98.     {
  99.         $this->eventDispatcher->dispatch(new LogEvent($event->getComposition(), $this->authenticationService->getUser(), EventLog::TYPE_COMPOSITION_EDITED));
  100.     }
  101. }