<?php
namespace App\EventSubscriber\Composition;
use App\Entity\Logs\EventLog;
use App\Event\Composition\CompositionCreatedEvent;
use App\Event\Composition\CompositionDeleteEvent;
use App\Event\Composition\CompositionEditedEvent;
use App\Event\Composition\CompositionPublishedEvent;
use App\Event\Composition\CompositionUnsubmittedEvent;
use App\Event\Composition\CompositionTakedDownEvent;
use App\Event\LogEvent;
use App\Service\AuthenticationService;
use App\Service\Mailer\CompositionMailer;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
class CompositionSubscriber implements EventSubscriberInterface
{
/**
* @var AuthenticationService
*/
private $authenticationService;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var CompositionMailer
*/
private $compositionMailer;
public function __construct(
AuthenticationService $authenticationService,
EventDispatcherInterface $eventDispatcher,
CompositionMailer $compositionMailer
)
{
$this->authenticationService = $authenticationService;
$this->eventDispatcher = $eventDispatcher;
$this->compositionMailer = $compositionMailer;
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
CompositionCreatedEvent::class => 'onCompositionCreatedEvent',
CompositionUnsubmittedEvent::class => 'onCompositionUnsubmittedEvent',
CompositionPublishedEvent::class => 'onCompositionPublishedEvent',
CompositionTakedDownEvent::class => 'onCompositionTakedDownEvent',
CompositionDeleteEvent::class => 'onCompositionDeleteEvent',
CompositionEditedEvent::class => 'onCompositionEditedEvent'
];
}
/**
* @param CompositionCreatedEvent $event
*/
public function onCompositionCreatedEvent(CompositionCreatedEvent $event): void
{
$this->eventDispatcher->dispatch(new LogEvent($event->getComposition(), $this->authenticationService->getUser(), EventLog::TYPE_COMPOSITION_CREATED));
}
/**
* @param CompositionUnsubmittedEvent $event
* @throws TransportExceptionInterface
*/
public function onCompositionUnsubmittedEvent(CompositionUnsubmittedEvent $event): void
{
$this->compositionMailer->sendCompositionUnsubmittedEmails($event->getComposition());
}
/**
* @param CompositionPublishedEvent $event
* @throws TransportExceptionInterface
*/
public function onCompositionPublishedEvent(CompositionPublishedEvent $event): void
{
$this->compositionMailer->sendCompositionPublishedEmails($event->getComposition());
}
/**
* @param CompositionTakedDownEvent $event
* @throws TransportExceptionInterface
*/
public function onCompositionTakedDownEvent(CompositionTakedDownEvent $event): void
{
$this->compositionMailer->sendCompositionTakedDownEmails($event->getComposition());
}
/**
* @param CompositionDeleteEvent $event
* @throws TransportExceptionInterface
*/
public function onCompositionDeleteEvent(CompositionDeleteEvent $event): void
{
//$this->compositionMailer->sendCompositionDeletemails($event->getComposition());
}
/**
* @param CompositionEditedEvent $event
* @throws TransportExceptionInterface
*/
public function onCompositionEditedEvent(CompositionEditedEvent $event): void
{
$this->eventDispatcher->dispatch(new LogEvent($event->getComposition(), $this->authenticationService->getUser(), EventLog::TYPE_COMPOSITION_EDITED));
}
}