src/EventSubscriber/PaginationParameterSanitizer.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. class PaginationParameterSanitizer implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents(): array
  9.     {
  10.         return [
  11.             KernelEvents::REQUEST => ['onKernelRequest'255],
  12.         ];
  13.     }
  14.     public function onKernelRequest(RequestEvent $event): void
  15.     {
  16.         if (!$event->isMainRequest()) {
  17.             return;
  18.         }
  19.         $request $event->getRequest();
  20.         if ($request->query->has('page')) {
  21.             $request->query->set('page'max(1$request->query->getInt('page'1)));
  22.         }
  23.     }
  24. }