vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Paginate/PaginationSubscriber.php line 17

Open in your IDE?
  1. <?php
  2. namespace Knp\Component\Pager\Event\Subscriber\Paginate;
  3. use Knp\Component\Pager\Event\BeforeEvent;
  4. use Knp\Component\Pager\Event\PaginationEvent;
  5. use Knp\Component\Pager\Pagination\SlidingPagination;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PaginationSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * Lazy-load state tracker
  11.      */
  12.     private bool $isLoaded false;
  13.     public function pagination(PaginationEvent $event): void
  14.     {
  15.         $event->setPagination(new SlidingPagination);
  16.         $event->stopPropagation();
  17.     }
  18.     public function before(BeforeEvent $event): void
  19.     {
  20.         // Do not lazy-load more than once
  21.         if ($this->isLoaded) {
  22.             return;
  23.         }
  24.         /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
  25.         $dispatcher $event->getEventDispatcher();
  26.         // hook all standard subscribers
  27.         $dispatcher->addSubscriber(new ArraySubscriber);
  28.         $dispatcher->addSubscriber(new Callback\CallbackSubscriber);
  29.         $dispatcher->addSubscriber(new Doctrine\ORM\QueryBuilderSubscriber);
  30.         $dispatcher->addSubscriber(new Doctrine\ORM\QuerySubscriber);
  31.         $dispatcher->addSubscriber(new Doctrine\ODM\MongoDB\QueryBuilderSubscriber);
  32.         $dispatcher->addSubscriber(new Doctrine\ODM\MongoDB\QuerySubscriber);
  33.         $dispatcher->addSubscriber(new Doctrine\ODM\PHPCR\QueryBuilderSubscriber);
  34.         $dispatcher->addSubscriber(new Doctrine\ODM\PHPCR\QuerySubscriber);
  35.         $dispatcher->addSubscriber(new Doctrine\CollectionSubscriber);
  36.         $dispatcher->addSubscriber(new Doctrine\DBALQueryBuilderSubscriber);
  37.         $dispatcher->addSubscriber(new PropelQuerySubscriber);
  38.         $dispatcher->addSubscriber(new SolariumQuerySubscriber());
  39.         $dispatcher->addSubscriber(new ElasticaQuerySubscriber());
  40.         $this->isLoaded true;
  41.     }
  42.     public static function getSubscribedEvents(): array
  43.     {
  44.         return [
  45.             'knp_pager.before' => ['before'0],
  46.             'knp_pager.pagination' => ['pagination'0],
  47.         ];
  48.     }
  49. }