src/FlexApp/EventSubscriber/ErrorNotifierSubscriber.php line 52

Open in your IDE?
  1. <?php
  2. namespace FlexApp\EventSubscriber;
  3. use Exception;
  4. use FlexApp\Events\BugEvent;
  5. use FlexApp\Events\Style43\CommentErrorEvent;
  6. use FlexApp\Events\Style43\GeneralErrorEvent;
  7. use FlexApp\Events\Style43\NotValidPortalApiServerRequestEvent;
  8. use FlexApp\Events\Style43\UserErrorEvent;
  9. use FlexApp\Service\DevsAndAdminsNotifier;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class ErrorNotifierSubscriber implements EventSubscriberInterface
  12. {
  13.     private DevsAndAdminsNotifier $notifier;
  14.     /**
  15.      * @param DevsAndAdminsNotifier $notifier
  16.      */
  17.     public function __construct(DevsAndAdminsNotifier $notifier)
  18.     {
  19.         $this->notifier $notifier;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         /*По каждому типу косяка уведомляем только тех
  24.         людей (разрабочиков/админов), которые имеют отношение
  25.         к данному типу косяка*/
  26.         return [
  27.             CommentErrorEvent::class                   => [
  28.                 ['notifyAboutCommentComponentError'0],
  29.             ],
  30.             UserErrorEvent::class                      => [
  31.                 ['notifyAboutUserComponentError'0],
  32.             ],
  33.             GeneralErrorEvent::class                   => [
  34.                 ['notifyAboutGeneralError'0],
  35.             ],
  36.             NotValidPortalApiServerRequestEvent::class => [
  37.                 ['notifyAboutGeneralError'0],
  38.             ],
  39.         ];
  40.     }
  41.     /**
  42.      * @param BugEvent $bugEvent
  43.      *
  44.      * @throws Exception
  45.      */
  46.     public function notifyAboutCommentComponentError(BugEvent $bugEvent)
  47.     {
  48.         $this->notifier->notify($bugEvent->getThrowable()->getMessage(), $bugEvent->getThrowable()->getTraceAsString(), 'comment_fails_emails');
  49.     }
  50.     /**
  51.      * @param \FlexApp\Events\BugEvent $bugEvent
  52.      *
  53.      * @throws Exception
  54.      */
  55.     public function notifyAboutGeneralError(BugEvent $bugEvent)
  56.     {
  57.         $this->notifier->notify($bugEvent->getThrowable()->getMessage(), $bugEvent->getThrowable()->getTraceAsString(), 'general_fails_emails');
  58.     }
  59.     /**
  60.      * @param \FlexApp\Events\BugEvent $bugEvent
  61.      *
  62.      * @throws Exception
  63.      */
  64.     public function notifyAboutUserComponentError(BugEvent $bugEvent)
  65.     {
  66.         $this->notifier->notify($bugEvent->getThrowable()->getMessage(), $bugEvent->getThrowable()->getTraceAsString(), 'user_fails_emails');
  67.     }
  68. }