API / Minn\Support / Lists

Lists final class

Minn\Support\Lists · public/minn/src/Minn/Support/Lists.php · 190 lines

List shaping behind the facade's array utilities: arguments over their defaults (wp_parse_args), plucking and filtering (WP_List_Util), the multi-field sort wp_list_sort() promises (loose comparison per field, first difference wins) and the row-shape conversions wpdb hands back for its OBJECT_K / ARRAY_A / ARRAY_N output formats.

Public

staticargs(mixed $args, mixed $defaults = array ( )): array#

Arguments as WordPress takes them (wp_parse_args): an object's properties, an array, or a query string, over the defaults.

$defaultsarray<array-key, mixed>
@return array<array-key, mixed>
staticpluck(array $items, string|int $field, string|int|null $indexKey = NULL): array#

One field of each item (wp_list_pluck), keyed as the list was, or by another field when one is named (items without it are appended); anything not an array or an object is passed over.

$itemsarray<array-key, mixed>
@return array<array-key, mixed>
staticfilter(array $items, array $fields, string $operator): array#

The items matching all the fields given (AND), any of them (OR), or none (NOT), compared loosely, keys kept; nothing for another operator.

$itemsarray<array-key, mixed>@param array<array-key, mixed> $fields
@return array<array-key, mixed>
staticitems(mixed $input): array#

A list as arguments give one (wp_parse_list): an array's entries trimmed, the empty ones dropped (keys kept); a string split on commas and whitespace.

@return array<int|string, string>
staticids(mixed $input): array#

Ids as arguments give them (wp_parse_id_list): each a whole number made positive, each once, in first-seen order.

@return list<int>
staticsort(array $items, array $orderby, bool $preserveKeys): array#

Items sorted by several fields, each ascending or descending.

$itemsarray<int|string, mixed>
$orderbyarray<string, string>field => ASC|DESC
@return array<int|string, mixed>
staticshapeRows(array $rows, string $output): array#

Rows of stdClass shaped for a wpdb output format: keyed by their first column (first row wins a duplicate key), associative, or numeric.

$rowslist<object>
@return array<int|string, mixed>
staticdescendants(array $items, int $rootId, callable $id, callable $parent, array $visited = array ( )): array#

Every descendant of one root in a flat parent-linked list, preorder (a child ahead of its own children), the shape _get_term_children and get_page_children walk. Visited ids guard against a parent cycle.

$itemslist<mixed>
$idcallable(mixed): int
$parentcallable(mixed): int
$visitedlist<int>
@return list<mixed>

Internals 1

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatekeyedByFirstColumn(array $rows): array#
$rowslist<object>
@return array<string, object>