src/App/Pager/Listener/PagerExceptionToHttpExceptionConverter.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Pager\Listener;
  3. use Pagerfanta\Exception\NotValidCurrentPageException;
  4. use Pagerfanta\Exception\NotValidMaxPerPageException;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  7. use Twig\Error\RuntimeError;
  8. class PagerExceptionToHttpExceptionConverter implements EventSubscriberInterface
  9. {
  10.     public function onException(ExceptionEvent $event): void
  11.     {
  12.         $exception $event->getThrowable();
  13.         if (!($exception instanceof RuntimeError)) {
  14.             return;
  15.         }
  16.         $previous $exception->getPrevious();
  17.         if (!($previous instanceof NotValidCurrentPageException) && !($previous instanceof NotValidMaxPerPageException)) {
  18.             return;
  19.         }
  20.         $event->setThrowable($previous);
  21.     }
  22.     /**
  23.      * @return array<string, array<int|string, array<int|string, int|string>|int|string>|string>
  24.      */
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             ExceptionEvent::class => ['onException'1024],
  29.         ];
  30.     }
  31. }