Skip to content
PHP Ecosystem
Explore

SortState

API reference › Debug Core › View › Grid › SortState

final readonly classPHPForge\Debug\View\Grid\SortState
Sourcesrc/View/Grid/SortState.php

Represents the active sort attribute and direction parsed from the sort query value.

PropertyTypeDescriptionDefined by
$attribute readonly constructorstringAttribute the rows are ordered by.SortState
$direction readonly constructor"asc"|"desc"Order applied to the attribute.SortState
MethodDescriptionDefined by
apply()Sorts rows with the natural ascending comparator, inverted for desc, then breaks ties in a fixed order.SortState
fromQuery() staticParses the query value, keeping it only when the attribute is sortable; otherwise applies the default.SortState
header()Builds the header cell of a sortable column, linking to the order the next click on it requests.SortState
panelUrl() staticBuilds the header-link factory of a panel grid, carrying the query parameters of the visible page.SortState
public function apply(list<PHPForge\Debug\View\Grid\TRow> $rows, Closure(PHPForge\Debug\View\Grid\TRow, PHPForge\Debug\View\Grid\TRow): int $compare, Closure(PHPForge\Debug\View\Grid\TRow, PHPForge\Debug\View\Grid\TRow): int|null $tieBreak = null): list<PHPForge\Debug\View\Grid\TRow>

Sorts rows with the natural ascending comparator, inverted for desc, then breaks ties in a fixed order.

Parameters

ParameterTypeDescription
$rowslist<PHPForge\Debug\View\Grid\TRow>Rows to order.
$compareClosure(PHPForge\Debug\View\Grid\TRow, PHPForge\Debug\View\Grid\TRow): intAscending comparator for the active attribute.
$tieBreakClosure(PHPForge\Debug\View\Grid\TRow, PHPForge\Debug\View\Grid\TRow): int|nullDirection-independent comparator applied to rows the main comparator considers equal, or null to keep their relative input order.

Returns

list<PHPForge\Debug\View\Grid\TRow>: Ordered rows.

public static function fromQuery(string|null $sort, list<string> $attributes, string $defaultAttribute, "asc"|"desc" $defaultDirection = 'asc'): self

Parses the query value, keeping it only when the attribute is sortable; otherwise applies the default.

Parameters

ParameterTypeDescription
$sortstring|nullRaw sort query value, optionally prefixed with - to request a descending order.
$attributeslist<string>Sortable attribute names.
$defaultAttributestringAttribute used when the query value names no sortable attribute.
$defaultDirection"asc"|"desc"Direction paired with the default attribute.

Returns

self: Sort state for the visible page.

public function header(string $attribute, string $label, Closure(string): string $url, bool $descendingFirst = false): PHPForge\Debug\View\Grid\SortHeader

Builds the header cell of a sortable column, linking to the order the next click on it requests.

Parameters

ParameterTypeDescription
$attributestringAttribute backing the header cell.
$labelstringVisible column label.
$urlClosure(string): stringBuilds the panel URL requesting a sort query value.
$descendingFirstboolWhether the first click on an inactive attribute requests a descending order.

Returns

SortHeader: Header cell announcing the active order.

public static function panelUrl(PHPForge\Debug\Panel\PanelRenderContext $context, array<array-key, mixed> $queryParams): Closure(string): string

Builds the header-link factory of a panel grid, carrying the query parameters of the visible page.

Parameters

ParameterTypeDescription
$contextPHPForge\Debug\Panel\PanelRenderContextState of the debugger request being rendered.
$queryParamsarray<array-key, mixed>Query parameters the header links are built from.

Returns

Closure(string): string: Builds the panel URL requesting a sort query value.