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

Open in your IDE?
  1. <?php
  2. namespace Knp\Component\Pager\Event\Subscriber\Paginate;
  3. use Knp\Component\Pager\Event\ItemsEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. /**
  6.  * Solarium query pagination.
  7.  *
  8.  * @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
  9.  */
  10. class SolariumQuerySubscriber implements EventSubscriberInterface
  11. {
  12.     public function items(ItemsEvent $event): void
  13.     {
  14.         if (is_array($event->target) && == count($event->target)) {
  15.             $values array_values($event->target);
  16.             [$client$query] = $values;
  17.             if ($client instanceof \Solarium\Client && $query instanceof \Solarium\QueryType\Select\Query\Query) {
  18.                 $query->setStart($event->getOffset())->setRows($event->getLimit());
  19.                 $solrResult $client->select($query);
  20.                 $event->items  iterator_to_array($solrResult->getIterator());
  21.                 $event->count  $solrResult->getNumFound();
  22.                 $event->setCustomPaginationParameter('result'$solrResult);
  23.                 $event->stopPropagation();
  24.             }
  25.         }
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             'knp_pager.items' => ['items'0], /* triggers before a standard array subscriber*/
  31.         ];
  32.     }
  33. }