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.     public function getLastPage(): float
  26.     {
  27.         if (>= $this->maxResults) {
  28.             return 1.;
  29.         }
  30.         return ceil($this->getTotalItems() / $this->maxResults) ?: 1.;
  31.     }
  32.     public function getTotalItems(): float
  33.     {
  34.         return (float) ($this->totalItems ?? $this->totalItems = \count($this->paginator));
  35.     }
  36.     public function getQuery(): Query
  37.     {
  38.         return $this->paginator->getQuery();
  39.     }
  40. }
  41. class_alias(Paginator::class, \ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator::class);