Centum\Paginator

The Paginator component is used for paginating large amounts of data practically.

How data is stored

Data is encapsulated in a class implementing Centum\Interfaces\Paginator\DataInterface. It is designed such that the entire dataset can be contained within a DataInterface object or can be retreived as and when it is needed.

DataInterface has 3 public methods:

  • public function getTotal(): int
  • public function toArray(): array
  • public function slice(int $offset, int $length): array

For data contained within a simple array, Centum\Paginator\Data\ArrayData will suffice.

Paginating

Centum\Paginator\Paginator is the main class of the Paginator component.

Centum\Paginator\Paginator(
    Centum\Interfaces\Paginator\DataInterface $data,
    int $itemsPerPage,
    string $urlPrefix
);

Centum\Paginator\Paginator implements Centum\Interfaces\Paginator\PaginatorInterface.

Centum\Paginator\Paginator has 6 public methods:

  • public function getData(): Centum\Interfaces\Paginator\DataInterface
  • public function getItemsPerPage(): int
  • public function getUrlPrefix(): string
  • public function getTotalItems(): int
  • public function getTotalPages(): int
  • public function getPage(int $pageNumber): Centum\Interfaces\Paginator\PageInterface

Paginator is responsible for creating Centum\Paginator\Page objects that represent a page of data.

Centum\Paginator\Page(
    Centum\Interfaces\Paginator\PaginatorInterface $paginator,
    int $pageNumber
);

Centum\Paginator\Page implements Centum\Interfaces\Paginator\PageInterface.

Centum\Paginator\Page has several public methods:

  • public function getPaginator(): Centum\Interfaces\Paginator\PaginatorInterface
  • public function getPageNumber(): int
  • public function getData(): array
  • public function getPreviousPageNumber(): int|null
  • public function getNextPageNumber(): int|null
  • public function getPageRange(int $i): array

Table of contents