<?php
namespace App\EventSubscriber\Composition;
use App\Entity\Logs\EventLog;
use App\Event\Composition\SongWriter\SongwriterConnectedToProfileEvent;
use App\Event\LogEvent;
use App\Service\AuthenticationService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SongWriterSubscriber implements EventSubscriberInterface
{
/**
* @var AuthenticationService
*/
private $authenticationService;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
public function __construct(
AuthenticationService $authenticationService,
EventDispatcherInterface $eventDispatcher
)
{
$this->authenticationService = $authenticationService;
$this->eventDispatcher = $eventDispatcher;
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
SongwriterConnectedToProfileEvent::class => 'onSongwriterConnectedToProfileEvent'
];
}
/**
* @param SongwriterConnectedToProfileEvent $event
*/
public function onSongwriterConnectedToProfileEvent(SongwriterConnectedToProfileEvent $event): void
{
$this->eventDispatcher->dispatch(new LogEvent($event->getSongWriter(), $this->authenticationService->getUser(), EventLog::TYPE_SONGWRITER_CONNECTED_TO_PROFILE));
}
}