vendor/api-platform/core/src/Doctrine/Orm/AbstractPaginator.php line 60

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Doctrine\Orm;
  12. use ApiPlatform\Exception\InvalidArgumentException;
  13. use ApiPlatform\State\Pagination\PartialPaginatorInterface;
  14. use Doctrine\ORM\Query;
  15. use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
  16. abstract class AbstractPaginator implements \IteratorAggregatePartialPaginatorInterface
  17. {
  18.     protected $paginator;
  19.     protected $iterator;
  20.     protected $firstResult;
  21.     protected $maxResults;
  22.     /**
  23.      * @throws InvalidArgumentException
  24.      */
  25.     public function __construct(DoctrinePaginator $paginator)
  26.     {
  27.         $query $paginator->getQuery();
  28.         if (null === ($firstResult $query->getFirstResult()) || null === $maxResults $query->getMaxResults()) {
  29.             throw new InvalidArgumentException(sprintf('"%1$s::setFirstResult()" or/and "%1$s::setMaxResults()" was/were not applied to the query.'Query::class));
  30.         }
  31.         $this->paginator $paginator;
  32.         $this->firstResult $firstResult;
  33.         $this->maxResults $maxResults;
  34.     }
  35.     public function getCurrentPage(): float
  36.     {
  37.         if (>= $this->maxResults) {
  38.             return 1.;
  39.         }
  40.         return floor($this->firstResult $this->maxResults) + 1.;
  41.     }
  42.     public function getItemsPerPage(): float
  43.     {
  44.         return (float) $this->maxResults;
  45.     }
  46.     public function getIterator(): \Traversable
  47.     {
  48.         return $this->iterator ?? $this->iterator $this->paginator->getIterator();
  49.     }
  50.     public function count(): int
  51.     {
  52.         return iterator_count($this->getIterator());
  53.     }
  54. }
  55. class_alias(AbstractPaginator::class, \ApiPlatform\Core\Bridge\Doctrine\Orm\AbstractPaginator::class);