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
| private | KEYS = 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', ), ) | |
| private | array $cache | |
| private | readonly Minn\Http\Router $router | Promoted from the constructor. |
| private | readonly Minn\Rest\Types $types | Promoted from the constructor. |
| private | readonly Minn\Rest\Taxonomies $taxonomies | Promoted from the constructor. |
Public
| new | __construct(Minn\Http\Router $router, Minn\Rest\Types $types, Minn\Rest\Taxonomies $taxonomies)# | ||||
| static | requested(array $query): ?array# | Null when _embed is absent; [] for every rel; otherwise the rels asked for. @return ?list<string> @return ?list<string> | |||
| method | decorate(Minn\Http\Request $request, Minn\Http\Response $response): Minn\Http\Response# | Decorates a finished response: the embed context, then _embedded, then the deferred _fields. | |||
| method | embedded(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.
@return array<string, mixed> | |||
| static | shape(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>
|
Internals 6
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | decorateItem(Minn\Http\Request $request, array $item, ?array $rels, ?string $kind): array# |
| |||
| private | answer(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. | |||
| private | target(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>} | |||
| private | kind(string $path): ?string# | Which key set a route's objects take in embed context; null for routes without one. | |||
| private | taxonomyBase(string $base): bool# | ||||
| private | context(string $kind, array $object): array# | The embed shape, with the fields plugin code registered for the item's type to show in embed. |
Nothing matches.