for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\Porpaginas;
/**
* @author Kevin Bond <[email protected]>
*/
abstract class Pager implements \Countable, \IteratorAggregate
{
final public function getNextPage(): ?int
$currentPage = $this->getCurrentPage();
if ($currentPage === $this->getLastPage()) {
return null;
}
return ++$currentPage;
final public function getPreviousPage(): ?int
$page = $this->getCurrentPage();
if (1 === $page) {
return --$page;
final public function getFirstPage(): int
return 1;
final public function getLastPage(): int
$totalCount = $this->totalCount();
if (0 === $totalCount) {
return (int) \ceil($totalCount / $this->getLimit());
final public function pagesCount(): int
return $this->getLastPage();
final public function haveToPaginate(): bool
return $this->pagesCount() > 1;
abstract public function getCurrentPage(): int;
abstract public function getLimit(): int;
* The result count for the current page.
abstract public function count(): int;
* The total result count.
abstract public function totalCount(): int;
* Return an iterator over selected windows of results of the paginatable.
abstract public function getIterator(): \Traversable;