vendor/friendsofsymfony/elastica-bundle/Doctrine/ORM/SliceFetcher.php line 9

Open in your IDE?
  1. <?php
  2. namespace FOS\ElasticaBundle\Doctrine\ORM;
  3. use Doctrine\ORM\QueryBuilder;
  4. use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
  5. use FOS\ElasticaBundle\Doctrine\SliceFetcherInterface;
  6. @trigger_error(sprintf('The %s class is deprecated since version 4.1 and will be removed in 5.0.'SliceFetcher::class), E_USER_DEPRECATED);
  7. /**
  8.  * @deprecated since 4.1 will be removed in 5.x.
  9.  * 
  10.  * Fetches a slice of objects.
  11.  *
  12.  * @author Thomas Prelot <tprelot@gmail.com>
  13.  */
  14. class SliceFetcher implements SliceFetcherInterface
  15. {
  16.     /**
  17.      * This method should remain in sync with Provider::fetchSlice until that method is deprecated and
  18.      * removed.
  19.      *
  20.      * {@inheritdoc}
  21.      */
  22.     public function fetch($queryBuilder$limit$offset, array $previousSlice, array $identifierFieldNames)
  23.     {
  24.         if (!$queryBuilder instanceof QueryBuilder) {
  25.             throw new InvalidArgumentTypeException($queryBuilder'Doctrine\ORM\QueryBuilder');
  26.         }
  27.         /*
  28.          * An orderBy DQL  part is required to avoid feching the same row twice.
  29.          * @see http://stackoverflow.com/questions/6314879/does-limit-offset-length-require-order-by-for-pagination
  30.          * @see http://www.postgresql.org/docs/current/static/queries-limit.html
  31.          * @see http://www.sqlite.org/lang_select.html#orderby
  32.          */
  33.         $orderBy $queryBuilder->getDQLPart('orderBy');
  34.         if (empty($orderBy)) {
  35.             $rootAliases $queryBuilder->getRootAliases();
  36.             foreach ($identifierFieldNames as $fieldName) {
  37.                 $queryBuilder->addOrderBy($rootAliases[0].'.'.$fieldName);
  38.             }
  39.         }
  40.         return $queryBuilder
  41.             ->setFirstResult($offset)
  42.             ->setMaxResults($limit)
  43.             ->getQuery()
  44.             ->getResult()
  45.         ;
  46.     }
  47. }