final class ListSort (View source)

Sort order requested through the sort query parameter of an API list endpoint.

Format: comma-separated fields, each optionally suffixed with :asc or :desc (default ascending), e.g. type,ttl:desc. Only fields on the endpoint's whitelist are accepted. An invalid value does not throw: it yields a sort with an error message, which the controller turns into a 400.

Constants

private MAX_FIELDS

Upper bound on sort keys.

Methods

static ListSort
fromQuery(string|null $raw, array $allowedFields)

Parse a sort query value against the endpoint's allowed fields.

array
fields()

The requested sort keys in order, for endpoints that sort in SQL. Every field is one of the allowed fields; empty when no sort was requested.

array
sortRows(array $rows)

Sort already-loaded rows (for endpoints that filter in PHP rather than SQL).

Details

static ListSort fromQuery(string|null $raw, array $allowedFields)

Parse a sort query value against the endpoint's allowed fields.

Parameters

string|null $raw
array $allowedFields

Return Value

ListSort

array fields()

The requested sort keys in order, for endpoints that sort in SQL. Every field is one of the allowed fields; empty when no sort was requested.

Return Value

array

array sortRows(array $rows)

Sort already-loaded rows (for endpoints that filter in PHP rather than SQL).

Integers compare numerically, everything else case-insensitively in natural order, and nulls sort first. usort() is stable, so rows that compare equal keep their original order.

Parameters

array $rows

Return Value

array