vendor\knplabs\knp-components\src\Knp\Component\Pager\Event\Subscriber\Paginate\ArraySubscriber.php line 11

Open in your IDE?
  1. <?php
  2. namespace Knp\Component\Pager\Event\Subscriber\Paginate;
  3. use ArrayObject;
  4. use Knp\Component\Pager\Event\ItemsEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ArraySubscriber implements EventSubscriberInterface
  7. {
  8.     public function items(ItemsEvent $event): void
  9.     {
  10.         if (is_array($event->target)) {
  11.             $event->count count($event->target);
  12.             $event->items array_slice(
  13.                 $event->target,
  14.                 $event->getOffset(),
  15.                 $event->getLimit()
  16.             );
  17.             $event->stopPropagation();
  18.         } elseif ($event->target instanceof ArrayObject) {
  19.             $event->count $event->target->count();
  20.             $event->items = new ArrayObject(array_slice(
  21.                 $event->target->getArrayCopy(),
  22.                 $event->getOffset(),
  23.                 $event->getLimit()
  24.             ));
  25.             $event->stopPropagation();
  26.         }
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             'knp_pager.items' => ['items', -1/* other data arrays should be analized first*/],
  32.         ];
  33.     }
  34. }