src/EventListener/ExceptionListener.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Service\SlackNotify;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. class ExceptionListener
  8. {
  9.     private $notify;
  10.     /**
  11.      * ExceptionListener constructor.
  12.      *
  13.      * @param SlackNotify $notify
  14.      */
  15.     public function __construct(SlackNotify $notify)
  16.     {
  17.         $this->notify $notify;
  18.     }
  19.     public function onKernelException(ExceptionEvent $event)
  20.     {
  21.         $exception $event->getThrowable();
  22.         $path $event->getRequest()->getPathInfo();
  23.         // Nie wysyła notyfikacji, jeżeli błąd to not found i adres strony nie zawiera wyrazu "api"
  24.         if ( !($exception instanceof NotFoundHttpException && strpos($path'api') === false ) ) {
  25.             $this->notify->send($exception);
  26.         }
  27.         
  28. //        if ( $exception instanceof \PDOException ) {
  29. //            $event->setResponse( new RedirectResponse('/admin/extra') );
  30. //            dump($event); die;
  31. //        }
  32.     }
  33. }