src/EventListener/AlertListener.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\AppEvents;
  4. use App\Event\AlertEvent;
  5. use App\Service\Mailer;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  8. class AlertListener implements EventSubscriberInterface{
  9.     private TokenStorageInterface $tokenStorage;
  10.     private Mailer $mailer;
  11.     public function __construct(TokenStorageInterface $tokenStorage,Mailer $mailer) {
  12.         $this->tokenStorage $tokenStorage;
  13.         $this->mailer $mailer;
  14.     }
  15.   /**
  16.    * Undocumented function
  17.    *
  18.    * @return array
  19.    */
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             AppEvents::GENERATE_ALERT => 'onGenerateAlert',
  24.         ];
  25.     }
  26.     
  27.     /**
  28.      * Undocumented function
  29.      *
  30.      * @param AlertEvent $alertEvent
  31.      * @return void
  32.      */
  33.     public function onGenerateAlert(AlertEvent $alertEvent):void
  34.     {
  35.         $this->mailer->alertNotification($alertEvent->getJob());
  36.     }
  37. }