src/EventSubscriber/CandidaciesEventSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Events\CandidaciesEvents;
  4. use App\Events\CandidacyEvent;
  5. use App\Events\SpontaneousEvent;
  6. use App\Service\Mailer\CandidacyMailer;
  7. use Psr\EventDispatcher\StoppableEventInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Contracts\EventDispatcher\Event;
  10. class CandidaciesEventSubscriber implements EventSubscriberInterface
  11. {
  12.     public function __construct(private CandidacyMailer $mailer)
  13.     {
  14.     }
  15.     public static function getSubscribedEvents()
  16.     {
  17.         return [
  18.             CandidacyEvent::class   => 'candidacy',
  19.             SpontaneousEvent::class => 'spontaneous',
  20.         ];
  21.     }
  22.     private function send(StoppableEventInterface $event)
  23.     {
  24.         $candidacy $event->getCandidacy();
  25.         $this->mailer->setCandidacy($candidacy);
  26.         $this->mailer->sendEmails();
  27.     }
  28.     public function candidacy(CandidacyEvent $event)
  29.     {
  30.        $this->send($event);
  31.     }
  32.     public function spontaneous(SpontaneousEvent $event)
  33.     {
  34.         $this->send($event);
  35.     }
  36. }