vendor/crea/event-bundle/src/EventSubscriber/CreaEventSubscriber.php line 49

Open in your IDE?
  1. <?php
  2. namespace Crea\EventBundle\EventSubscriber;
  3. use Crea\EventBundle\Console\CreaEventConsoleDisplayInterface;
  4. use Crea\EventBundle\Helper\EventEmailSenderHelper;
  5. use Crea\EventBundle\Manager\Level_1\EventLogManager;
  6. use Crea\EventBundle\Model\CreaEvent;
  7. use Crea\EventBundle\Entity\CreaEventCodes;
  8. use Crea\EventBundle\Repository\EventModelRepository;
  9. use Exception;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpKernel\KernelInterface;
  12. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  13. class CreaEventSubscriber implements EventSubscriberInterface
  14. {
  15.     protected EventModelRepository $eventModelRepository;
  16.     protected KernelInterface $kernel;
  17.     protected CreaEventConsoleDisplayInterface $creaEventConsoleDisplay;
  18.     protected EventLogManager $eventLogManager;
  19.     protected EventEmailSenderHelper $eventEmailSenderHelper;
  20.     public function __construct(EventModelRepository $eventModelRepository,
  21.                                 KernelInterface $kernel,
  22.                                 CreaEventConsoleDisplayInterface $creaEventConsoleDisplay,
  23.                                 EventLogManager $eventLogManager,
  24.                                 EventEmailSenderHelper $eventEmailSenderHelper)
  25.     {
  26.         $this->eventModelRepository $eventModelRepository;
  27.         $this->kernel $kernel;
  28.         $this->creaEventConsoleDisplay $creaEventConsoleDisplay;
  29.         $this->eventLogManager $eventLogManager;
  30.         $this->eventEmailSenderHelper $eventEmailSenderHelper;
  31.     }
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         $events = [];
  35.         foreach (CreaEventCodes::EVENT_MODEL_CODES as $eventCode) {
  36.             $events[$eventCode] = [['handle'256]];
  37.         }
  38.         return $events;
  39.     }
  40.     /**
  41.      * @throws Exception
  42.      * @throws TransportExceptionInterface
  43.      */
  44.     public function handle(CreaEvent $creaEvent)
  45.     {
  46.         if ($this->kernel->getEnvironment() === "dev" && $creaEvent->isConsoleDisplayed()) {
  47.             if ($creaEvent->getEventType()->getCode() === CreaEventCodes::EVENT_TYPE_ERROR_CODE) {
  48.                 $this->creaEventConsoleDisplay->displayException($creaEvent);
  49.             }
  50.             elseif ($creaEvent->getEventType()->getCode() === CreaEventCodes::EVENT_TYPE_WARNING_CODE) {
  51.                 $this->creaEventConsoleDisplay->displayWarning($creaEvent);
  52.             }
  53.             else {
  54.                 $this->creaEventConsoleDisplay->displayInformation($creaEvent);
  55.             }
  56.         }
  57.         if ($creaEvent->isDatabaseLogged()) {
  58.             $this->eventLogManager->logEvent($creaEvent);
  59.         }
  60.         if ($creaEvent->isEmailSend()) {
  61.             $this->eventEmailSenderHelper->sendEmail($creaEvent);
  62.         }
  63.     }
  64. }