src/EventSubscriber/SplitFirstPagePaginationSubscriber.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Attribute\SplitFirstPagePagination;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class SplitFirstPagePaginationSubscriber implements EventSubscriberInterface
  8. {
  9.     public function onKernelController(ControllerEvent $event): void
  10.     {
  11.         $controller $event->getController();
  12.         if (!is_array($controller)) {
  13.             return;
  14.         }
  15.         $reflection = new \ReflectionMethod($controller[0], $controller[1]);
  16.         if ([] === $reflection->getAttributes(SplitFirstPagePagination::class)) {
  17.             return;
  18.         }
  19.         $event->getRequest()->attributes->set(SplitFirstPagePagination::REQUEST_ATTRIBUTEtrue);
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             KernelEvents::CONTROLLER => 'onKernelController',
  25.         ];
  26.     }
  27. }