API / Minn\Rest / RestMeta

RestMeta final class

Minn\Rest\RestMeta · public/minn/src/Minn/Rest/RestMeta.php · 265 lines

An object's meta field over REST, from the keys registered to show there (probe rest-meta). Each key answers under its REST name (its own, or show_in_rest's name): those for every subtype, then the object's subtype's, left out of a context their schema does not name. A single key reads its first stored value (its default, or its type's empty value, when none), a multiple key each one; each value is checked against the key's schema (null when it does not fit, the empty value of a scalar type for '') and cast, or handed to the key's prepare callback. A write goes key by key in registration order: null (or an empty list) deletes, a value its schema refuses is a 400, and a key the user may not edit is a 403 (an unchanged single value is left alone first). The errors are gathered; the first is the answer, with the others beside it.

Constants and properties

privateSCALARS = array ( 0 => 'string', 1 => 'boolean', 2 => 'integer', 3 => 'number', )

Public

staticread(string $objectType, int $objectId, string $subtype, ?string $context = NULL): array#

The meta field of an object in a context (the one the request answers in, when none is named), keyed by REST name. @return array<string, mixed>

@return array<string, mixed>
staticvalue(string $objectType, int $objectId, string $key, array $field, WP_REST_Request $request): mixed#

One field's value for an object: a single key's first stored value (its default when none), a multiple key's each one, prepared for the response.

$fieldarray<string, mixed>
staticwriteFrom(WP_REST_Request $request, string $objectType, int $objectId, string $subtype): void#

Applies the meta a write request names, when it names any.

staticwrite(string $objectType, int $objectId, string $subtype, array $meta): void#

Applies a request's meta to an object; the gathered refusals are thrown.

staticerrors(string $objectType, int $objectId, string $subtype, array $meta): array#

Applies a request's meta to an object, key by key in registration order; the refusals come back. @return list<\WP_Error>

@return list<\WP_Error>
staticfields(string $objectType, string $subtype): array#

The keys registered to show in REST for an object type and subtype, each with its REST name, whether it is single, its schema (a multiple key's an array of its own) and its prepare callback; keys of a type REST does not know are left out.

@return array<string, array{name: string, single: bool, schema: array<string, mixed>, prepare_callback: mixed}>
staticprepare(mixed $value, array $field, WP_REST_Request $request): mixed#

A value for the response: through the field's prepare callback, or checked against its schema (null when it does not fit) and cast. @param array<string, mixed> $field

$fieldarray<string, mixed>
staticstore(string $objectType, int $objectId, string $subtype, string $key, array $field, mixed $value): ?WP_Error#

A single key stored: an unchanged value is left alone, then the user must be allowed to edit it. @param array<string, mixed> $field

$fieldarray<string, mixed>
staticstoreAll(string $objectType, int $objectId, string $subtype, string $key, array $field, array $values): ?WP_Error#

A multiple key stored as a list, once the user may edit it. @param array<string, mixed> $field @param array<mixed> $values

$fieldarray<string, mixed>@param array<mixed> $values
staticdelete(string $objectType, int $objectId, string $key, array $field): ?WP_Error#

A key deleted once the user may delete it (a single key's invalid stored value refuses null). @param array<string, mixed> $field

$fieldarray<string, mixed>
staticsame(string $objectType, string $subtype, string $key, array $field, mixed $stored, mixed $value): bool#

Whether a value sanitizes to what is stored (scalar types compared as the text the store keeps). @param array<string, mixed> $field

$fieldarray<string, mixed>
staticemptyValue(string $type): mixed#

A type's empty value: '' for a string, false, 0, or an empty list.

Internals 7

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

privateupdate(string $objectType, int $objectId, string $subtype, string $key, array $field, mixed $value): ?WP_Error#
$fieldarray<string, mixed>
privatereplaceAll(string $objectType, int $objectId, string $subtype, string $key, array $field, array $values): ?WP_Error#

A multiple key set to a list: values already stored once are kept, the rest of the stored ones removed and the new ones added.

$fieldarray<string, mixed>
$valuesarray<mixed>
privaterefused(string $code, string $name): WP_Error#
privatefailed(string $key, string $name): WP_Error#
privatenullStored(string $name): WP_Error#
privategathered(array $errors): Minn\RestError#

The gathered errors as one refusal: the first answers, with its earlier data beside it, and the rest as additional errors. @param list<\WP_Error> $errors

$errorslist<\WP_Error>
privaterequest(): WP_REST_Request#