-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paginator.php
55 lines (46 loc) · 1.14 KB
/
Paginator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Doctrine\Orm;
use ApiPlatform\State\Pagination\PaginatorInterface;
use Doctrine\ORM\Query;
/**
* Decorates the Doctrine ORM paginator.
*
* @author Kévin Dunglas <[email protected]>
*/
final class Paginator extends AbstractPaginator implements PaginatorInterface, QueryAwareInterface
{
private ?int $totalItems = null;
/**
* {@inheritdoc}
*/
public function getLastPage(): float
{
if (0 >= $this->maxResults) {
return 1.;
}
return ceil($this->getTotalItems() / $this->maxResults) ?: 1.;
}
/**
* {@inheritdoc}
*/
public function getTotalItems(): float
{
return (float) ($this->totalItems ?? $this->totalItems = \count($this->paginator));
}
/**
* {@inheritdoc}
*/
public function getQuery(): Query
{
return $this->paginator->getQuery();
}
}