API / Minn\Rest / MediaObject

MediaObject final readonly class

Minn\Rest\MediaObject · public/minn/src/Minn/Rest/MediaObject.php · 171 lines

The wp/v2 media object, view and edit context.

Constants and properties

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Media\Uploads $uploads

Promoted from the constructor.

privatereadonly Minn\Front\Permalinks $permalinks

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

privatereadonly Minn\Rest\Types $types

Promoted from the constructor.

Public

new__construct(Minn\Content\Posts $posts, Minn\Media\Uploads $uploads, Minn\Front\Permalinks $permalinks, Minn\Rest\RestUrl $url, Minn\Rest\Caller $caller, Minn\Rest\Types $types)#
methodbuild(Minn\Content\PostRecord $p, Minn\Rest\Context $context): array#

An attachment in the context asked for, as rest_block_hooks_post_types has it (attachments only when a plugin lists them), through rest_prepare_attachment when a plugin hooks it.

methodurl(): Minn\Rest\RestUrl#

The REST URL builder.

methodlinks(Minn\Content\PostRecord $p, Minn\Rest\Context $context): array#

The attachment's links in a context: itself (with the methods the caller may use), its collection and type, its author, replies, the post it is attached to, and in the edit context the actions the caller may take; curies when any rel is the API's own.

@return array<string, list<array<string, mixed>>>

Internals 2

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

privatebuildFields(Minn\Content\PostRecord $p, Minn\Rest\Context $context): array#

The wp/v2 media shape, with the edit-context fields when asked.

privatedetails(array $meta, string $mime, string $attached): array#

media_details: the stored metadata as it is, its sizes each with its MIME type and URL, and the full size after them when there are any (an attachment without sizes, audio among them, has an empty object).

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