final class ListPaging (View source)

Opt-in paging and substring filtering for API list endpoints. paginate() and filterContains() serve lists that are already loaded, e.g. records, which come from the PowerDNS API in API backend mode; isPastEnd() and extra() also serve lists paged in SQL, such as change requests.

Nothing is paged without per_page (or with 0); with it, page starts at 1 and per_page is capped. GET /change-requests also caps an unpaged list and then adds the pagination object, since its history keeps growing.

Methods

static array
parameters(mixed $page, mixed $perPage, int $maxPageSize)

No description

static bool
isPastEnd(int $page, int $perPage, int $total)

Whether the page lies beyond the last one. Checked before any offset is computed, so a huge page number can never overflow ($page - 1) * $perPage.

static array
extra(int $page, int $perPage, int $total)

The pagination object for a paged response, or nothing when per_page was not given.

static array
paginate(array $items, int $page, int $perPage)

Page a list that is already filtered and sorted. The total counts every item passed in, so pass only what the caller may see.

static array
filterContains(array $items, string $needle, callable $values)

Keep the items with a value that contains the needle, ignoring case.

Details

static array parameters(mixed $page, mixed $perPage, int $maxPageSize)

No description

Parameters

mixed $page
mixed $perPage
int $maxPageSize

Return Value

array

[page, perPage]; perPage 0 means "return everything"

static bool isPastEnd(int $page, int $perPage, int $total)

Whether the page lies beyond the last one. Checked before any offset is computed, so a huge page number can never overflow ($page - 1) * $perPage.

Parameters

int $page
int $perPage
int $total

Return Value

bool

static array extra(int $page, int $perPage, int $total)

The pagination object for a paged response, or nothing when per_page was not given.

Parameters

int $page
int $perPage
int $total

Return Value

array

Extra top-level response fields

static array paginate(array $items, int $page, int $perPage)

Page a list that is already filtered and sorted. The total counts every item passed in, so pass only what the caller may see.

Parameters

array $items
int $page
int $perPage

Return Value

array

[items of the page, extra response fields]

static array filterContains(array $items, string $needle, callable $values)

Keep the items with a value that contains the needle, ignoring case.

An empty needle keeps everything.

Parameters

array $items
string $needle
callable $values

Returns the values of an item to search

Return Value

array