vendor/babdev/pagerfanta-bundle/EventListener/ConvertNotValidMaxPerPageToNotFoundListener.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace BabDev\PagerfantaBundle\EventListener;
  3. use Pagerfanta\Exception\NotValidMaxPerPageException;
  4. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  5. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. final class ConvertNotValidMaxPerPageToNotFoundListener
  8. {
  9.     /**
  10.      * @param GetResponseForExceptionEvent|ExceptionEvent $event
  11.      */
  12.     public function onKernelException(object $event): void
  13.     {
  14.         if (!($event instanceof GetResponseForExceptionEvent) && !($event instanceof ExceptionEvent)) {
  15.             throw new \InvalidArgumentException(sprintf('The $event argument of %s() must be an instance of %s or %s, a %s was given.'__METHOD__GetResponseForExceptionEvent::class, ExceptionEvent::class, \get_class($event)));
  16.         }
  17.         if (method_exists($event'getThrowable')) {
  18.             $throwable $event->getThrowable();
  19.         } else {
  20.             // Support for Symfony 4.3 and before
  21.             $throwable $event->getException();
  22.         }
  23.         if ($throwable instanceof NotValidMaxPerPageException) {
  24.             $notFoundHttpException = new NotFoundHttpException('Page Not Found'$throwable);
  25.             if (method_exists($event'setThrowable')) {
  26.                 $event->setThrowable($notFoundHttpException);
  27.             } else {
  28.                 // Support for Symfony 4.3 and before
  29.                 $event->setException($notFoundHttpException);
  30.             }
  31.         }
  32.     }
  33. }