ListPaging
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
No description
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.
The pagination object for a paged response, or nothing when per_page was not given.
Page a list that is already filtered and sorted. The total counts every item passed in, so pass only what the caller may see.
Keep the items with a value that contains the needle, ignoring case.
Details
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.
An empty needle keeps everything.