vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber/UsesPaginator.php line 17

Open in your IDE?
  1. <?php
  2. namespace Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Knp\Component\Pager\Event\ItemsEvent;
  6. use Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber;
  7. use Doctrine\ORM\Query;
  8. use Doctrine\ORM\Tools\Pagination\Paginator;
  9. use Doctrine\ORM\Tools\Pagination\CountWalker;
  10. class UsesPaginator implements EventSubscriberInterface
  11. {
  12.     const HINT_FETCH_JOIN_COLLECTION 'knp_paginator.fetch_join_collection';
  13.     public function items(ItemsEvent $event)
  14.     {
  15.         if (!class_exists('Doctrine\ORM\Tools\Pagination\Paginator')) {
  16.             return;
  17.         }
  18.         if (!$event->target instanceof Query) {
  19.             return;
  20.         }
  21.         $event->stopPropagation();
  22.         $useOutputWalkers false;
  23.         if (isset($event->options['wrap-queries'])) {
  24.             $useOutputWalkers $event->options['wrap-queries'];
  25.         }
  26.         $event->target
  27.             ->setFirstResult($event->getOffset())
  28.             ->setMaxResults($event->getLimit())
  29.             ->setHint(CountWalker::HINT_DISTINCT$event->options[PaginatorInterface::DISTINCT])
  30.         ;
  31.         $fetchJoinCollection true;
  32.         if ($event->target->hasHint(self::HINT_FETCH_JOIN_COLLECTION)) {
  33.             $fetchJoinCollection $event->target->getHint(self::HINT_FETCH_JOIN_COLLECTION);
  34.         } else if (isset($event->options[PaginatorInterface::DISTINCT])) {
  35.             $fetchJoinCollection $event->options[PaginatorInterface::DISTINCT];
  36.         }
  37.         $paginator = new Paginator($event->target$fetchJoinCollection);
  38.         $paginator->setUseOutputWalkers($useOutputWalkers);
  39.         if (($count $event->target->getHint(QuerySubscriber::HINT_COUNT)) !== false) {
  40.             $event->count intval($count);
  41.         } else {
  42.             $event->count count($paginator);
  43.         }
  44.         $event->items iterator_to_array($paginator);
  45.     }
  46.     public static function getSubscribedEvents()
  47.     {
  48.         return array(
  49.             'knp_pager.items' => array('items'0)
  50.         );
  51.     }
  52. }