vendor/api-platform/core/src/Doctrine/Orm/Paginator.php line 24

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\State\Pagination\PaginatorInterface;
  13. use Doctrine\ORM\Query;
  14. /**
  15.  * Decorates the Doctrine ORM paginator.
  16.  *
  17.  * @author Kévin Dunglas <dunglas@gmail.com>
  18.  */
  19. final class Paginator extends AbstractPaginator implements PaginatorInterfaceQueryAwareInterface
  20. {
  21.     private ?int $totalItems null;
  22.     /**
  23.      * {@inheritdoc}
  24.      */
  25.     public function getLastPage(): float
  26.     {
  27.         if (>= $this->maxResults) {
  28.             return 1.;
  29.         }
  30.         return ceil($this->getTotalItems() / $this->maxResults) ?: 1.;
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function getTotalItems(): float
  36.     {
  37.         return (float) ($this->totalItems ?? $this->totalItems \count($this->paginator));
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function getQuery(): Query
  43.     {
  44.         return $this->paginator->getQuery();
  45.     }
  46. }