API / Minn\Rest / ViewConfigPatch

ViewConfigPatch final class

Minn\Rest\ViewConfigPatch · public/minn/src/Minn/Rest/ViewConfigPatch.php · 151 lines

A patch to a view configuration (WP_View_Config_Data; probe rest-view-config), applied as the reference applies it. Only schema version 1 is taken, and only the documented keys: each is set (its value replaced), merged (maps merged key by key, lists joined with their members matched by identity), replaced (merged, but lists replaced whole) or removed (keys from a map, members from a list by identity). A null in a patch removes what it names. What a caller got wrong comes back as problems: the function to name and the words.

Constants and properties

constKEYS = array ( 0 => 'default_view', 1 => 'default_layouts', 2 => 'view_list', 3 => 'form', )
privateSHAPE = 'A view configuration patch value must match the shape of the value it patches: a list merges into a list, and an associative array into an associative array.'
privatearray $problems
privatereadonly bool $replaceLists

Promoted from the constructor.

Public

new__construct(bool $replaceLists)#
staticapply(array $config, array $patch, mixed $version, string $mode): array#

A configuration with a patch applied in a mode (set, merge, replace, remove), and the problems met: [function or null for the mode's own method, words].

$configarray<string, mixed>
$patcharray<mixed>
@return array{0: array<string, mixed>, 1: list<array{0: ?string, 1: string}>}
staticstripNulls(mixed $value): mixed#

A value with every null in it removed, lists closed up.

staticidentity(mixed $item): ?string#

The identity a list member is matched by: a word itself, a map's id or slug; null for none.

Internals 3

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

privatemerge(mixed $current, mixed $incoming): mixed#

Incoming merged over current: maps key by key, lists by identity (or replaced), anything else replaced; a mismatched shape is a problem and leaves current.

privatemergeList(array $current, array $incoming): array#
$currentlist<mixed>
$incominglist<mixed>
@return list<mixed>
privateremove(mixed $current, mixed $spec): mixed#

Keys removed from a map (a list of keys, or a key mapped to what to remove inside it); members removed from a list by identity.