API / Minn\Rest / Embed

Embed final class

Minn\Rest\Embed · public/minn/src/Minn/Rest/Embed.php · 219 lines

The _embed decoration and the embed context. Every embeddable link in an object's _links is answered in-process as the same caller with context=embed and placed under _embedded[rel], an error as the error itself; a rel whose every embed came back empty is left out, while an empty list beside a full one stays (wp:term keeps its empty tags list next to the categories). Lists have _fields applied per item before the links are read, so a _fields value without _links embeds nothing there; a single object embeds first and is filtered afterwards. The embed context is the view object cut to the reference's key set for that kind of item.

Constants and properties

privateKEYS = array ( 'post' => array ( 0 => 'id', 1 => 'date', 2 => 'slug', 3 => 'type', 4 => 'link', 5 => 'title', 6 => 'excerpt', 7 => 'author', 8 => 'featured_media', 9 => '_links', ), 'media' => array ( 0 => 'id', 1 => 'date', 2 => 'slug', 3 => 'type', 4 => 'link', 5 => 'title', 6 => 'author', 7 => 'featured_media', 8 => 'caption', 9 => 'alt_text', 10 => 'media_type', 11 => 'mime_type', 12 => 'media_details', 13 => 'source_url', 14 => '_links', ), 'user' => array ( 0 => 'id', 1 => 'name', 2 => 'url', 3 => 'description', 4 => 'link', 5 => 'slug', 6 => 'avatar_urls', 7 => '_links', ), 'term' => array ( 0 => 'id', 1 => 'link', 2 => 'name', 3 => 'slug', 4 => 'taxonomy', 5 => '_links', ), 'comment' => array ( 0 => 'id', 1 => 'parent', 2 => 'author', 3 => 'author_name', 4 => 'author_url', 5 => 'date', 6 => 'content', 7 => 'link', 8 => 'type', 9 => 'author_avatar_urls', 10 => '_links', ), )
privatearray $cache
privatereadonly Minn\Http\Router $router

Promoted from the constructor.

privatereadonly Minn\Rest\Types $types

Promoted from the constructor.

privatereadonly Minn\Rest\Taxonomies $taxonomies

Promoted from the constructor.

Public

new__construct(Minn\Http\Router $router, Minn\Rest\Types $types, Minn\Rest\Taxonomies $taxonomies)#
staticrequested(array $query): ?array#

Null when _embed is absent; [] for every rel; otherwise the rels asked for. @return ?list<string>

@return ?list<string>
methoddecorate(Minn\Http\Request $request, Minn\Http\Response $response): Minn\Http\Response#

Decorates a finished response: the embed context, then _embedded, then the deferred _fields.

methodembedded(Minn\Http\Request $request, array $item, array $rels): array#

A response's data with its embeddable links answered (the runtime's WP_REST_Server::embed_links): every rel when none is named.

$itemarray<string, mixed>@param list<string> $rels
@return array<string, mixed>
staticshape(string $type, array $item): array#

An item cut to the embed shape of its object type (a post type, a taxonomy, attachment, user or comment); any other kept whole. @param array<string, mixed> $item @return array<string, mixed>

$itemarray<string, mixed>@return array<string, mixed>

Internals 6

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

privatedecorateItem(Minn\Http\Request $request, array $item, ?array $rels, ?string $kind): array#
$rels?list<string>
privateanswer(Minn\Http\Request $request, string $href): ?array#

The linked object in embed context; an error answer as the error itself (probe rest-server-methods); null when nothing came back.

privatetarget(string $href): array#

A REST href in either URL form, as the route path and its query. @return array{0: string, 1: array<string, string>}

@return array{0: string, 1: array<string, string>}
privatekind(string $path): ?string#

Which key set a route's objects take in embed context; null for routes without one.

privatetaxonomyBase(string $base): bool#
privatecontext(string $kind, array $object): array#

The embed shape, with the fields plugin code registered for the item's type to show in embed.