<?php
namespace App\EventSubscriber;
use App\Events\CandidaciesEvents;
use App\Events\CandidacyEvent;
use App\Events\SpontaneousEvent;
use App\Service\Mailer\CandidacyMailer;
use Psr\EventDispatcher\StoppableEventInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\Event;
class CandidaciesEventSubscriber implements EventSubscriberInterface
{
public function __construct(private CandidacyMailer $mailer)
{
}
public static function getSubscribedEvents()
{
return [
CandidacyEvent::class => 'candidacy',
SpontaneousEvent::class => 'spontaneous',
];
}
private function send(StoppableEventInterface $event)
{
$candidacy = $event->getCandidacy();
$this->mailer->setCandidacy($candidacy);
$this->mailer->sendEmails();
}
public function candidacy(CandidacyEvent $event)
{
$this->send($event);
}
public function spontaneous(SpontaneousEvent $event)
{
$this->send($event);
}
}