src/Infrastructure/Shared/Symfony/EventSubscriber/ExceptionSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Shared\Symfony\EventSubscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Symfony\Component\Messenger\Exception\ValidationFailedException;
  8. class ExceptionSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents()
  11.     {
  12.         // return the subscribed events, their methods and priorities
  13.         return [
  14.             KernelEvents::EXCEPTION => [
  15.                 ['processException'],
  16.             ],
  17.         ];
  18.     }
  19.     public function processException(ExceptionEvent $event)
  20.     {
  21.         $throwable $event->getThrowable();
  22.         if ($throwable instanceof ValidationFailedException) {
  23.             dump($throwable->getViolations());
  24.             exit;
  25.         }
  26.     }
  27. }