src/EventSubscriber/AccountDeletedExceptionEventSubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Exception\AccountDeletedException;
  4. use Junker\JSendResponse\JSendFailResponse;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class AccountDeletedExceptionEventSubscriber implements EventSubscriberInterface
  9. {
  10.     public function onKernelException(ExceptionEvent $event): void
  11.     {
  12.         $exception $event->getThrowable();
  13.         if (!($exception instanceof AccountDeletedException)) {
  14.             return;
  15.         }
  16.         $event->setResponse(
  17.             new JSendFailResponse('This account has been deleted.'JSendFailResponse::HTTP_FORBIDDEN)
  18.         );
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             KernelEvents::EXCEPTION => 'onKernelException',
  24.         ];
  25.     }
  26. }