src/Service/Airbrake/EventSubscriber.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Service\Airbrake;
  3. use Symfony\Component\Console\ConsoleEvents;
  4. use Symfony\Component\Console\Event\ConsoleErrorEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class EventSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var Notifier
  12.      */
  13.     protected $notifier;
  14.     /**
  15.      * @var array
  16.      */
  17.     protected $ignoredExceptions;
  18.     /**
  19.      * @param Notifier $notifier
  20.      * @param array    $ignoredExceptions
  21.      */
  22.     public function __construct(Notifier $notifier, array $ignoredExceptions = [])
  23.     {
  24.         $this->notifier $notifier;
  25.         $this->ignoredExceptions $ignoredExceptions;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             KernelEvents::EXCEPTION => ['onKernelException', -128],
  31.             ConsoleEvents::ERROR => ['onConsoleError', -128],
  32.             //ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128],
  33.         ];
  34.     }
  35.     /**
  36.      * @param ExceptionEvent $event
  37.      */
  38.     public function onKernelException(ExceptionEvent $event)
  39.     {
  40.         $exception $event->getThrowable();
  41.         foreach ($this->ignoredExceptions as $ignoredException) {
  42.             if ($exception instanceof $ignoredException) {
  43.                 return;
  44.             }
  45.         }
  46.         // SPECIAL CASE : IGNORE missing files IN STAGING only
  47.         $message $exception->getMessage();
  48.         if ((false !== stripos($message'hosts/staging')) && (false !== stripos($message'/ed/')) && (false !== stripos($message'does not'))) {
  49.             return;
  50.         }
  51.         $this->notifier->notify($exception);
  52.     }
  53.     /**
  54.      * @param ConsoleErrorEvent $event
  55.      */
  56.     public function onConsoleError(ConsoleErrorEvent $event)
  57.     {
  58.         $error $event->getError();
  59.         $this->notifier->notify($error);
  60.     }
  61. }