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.     /**
  22.      * @var int|null
  23.      */
  24.     private $totalItems;
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function getLastPage(): float
  29.     {
  30.         if (>= $this->maxResults) {
  31.             return 1.;
  32.         }
  33.         return ceil($this->getTotalItems() / $this->maxResults) ?: 1.;
  34.     }
  35.     /**
  36.      * {@inheritdoc}
  37.      */
  38.     public function getTotalItems(): float
  39.     {
  40.         return (float) ($this->totalItems ?? $this->totalItems \count($this->paginator));
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function getQuery(): Query
  46.     {
  47.         return $this->paginator->getQuery();
  48.     }
  49. }
  50. class_alias(Paginator::class, \ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator::class);