vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/CollectionSubscriber.php line 11

Open in your IDE?
  1. <?php
  2. namespace Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine;
  3. use Doctrine\Common\Collections\Collection;
  4. use Knp\Component\Pager\Event\ItemsEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class CollectionSubscriber implements EventSubscriberInterface
  7. {
  8.     public function items(ItemsEvent $event): void
  9.     {
  10.         if ($event->target instanceof Collection) {
  11.             $event->count $event->target->count();
  12.             $event->items $event->target->slice(
  13.                 $event->getOffset(),
  14.                 $event->getLimit()
  15.             );
  16.             $event->stopPropagation();
  17.         }
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             'knp_pager.items' => ['items'0],
  23.         ];
  24.     }
  25. }