<?php
namespace App\EventSubscriber;
use App\Attribute\SplitFirstPagePagination;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class SplitFirstPagePaginationSubscriber implements EventSubscriberInterface
{
public function onKernelController(ControllerEvent $event): void
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
if ([] === $reflection->getAttributes(SplitFirstPagePagination::class)) {
return;
}
$event->getRequest()->attributes->set(SplitFirstPagePagination::REQUEST_ATTRIBUTE, true);
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
];
}
}