MediaController final readonly class
Minn\Rest\MediaController · public/minn/src/Minn/Rest/MediaController.php · 294 lines
wp/v2/media: list, single, upload on both transports (multipart field "file", or a raw body with Content-Disposition), field edits, and force delete with the files.
Uses 25 (show)
Constants and properties
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Media\Writer $library | Promoted from the constructor. |
| private | readonly Minn\Rest\MediaObject $object | Promoted from the constructor. |
| private | readonly Minn\Rest\Caller $caller | Promoted from the constructor. |
| private | readonly Minn\Rest\PostsController $reads | Promoted from the constructor. |
Public
| new | __construct(Minn\Content\Posts $posts, Minn\Media\Writer $library, Minn\Rest\MediaObject $object, Minn\Rest\Caller $caller, Minn\Rest\PostsController $reads)# | |
| method | list(Minn\Http\Request $request, string $base): Minn\Http\ResponseGET /wp/v2/{base:media} (public)# | The media list: the post lists' own path for attachments (probe rest-media-lists), each item in the media shape. |
| method | single(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/media/{id:[\d]+} (public; attachment {id} must exist; edit context: cap edit_post on {id})# | One attachment. |
| method | create(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/media (cap upload_files)# | Uploads a file and creates its attachment. |
| method | update(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/media/{id:[\d]+} (cap edit_post on {id}; attachment {id} must exist)PUT /wp/v2/media/{id:[\d]+} (cap edit_post on {id}; attachment {id} must exist)PATCH /wp/v2/media/{id:[\d]+} (cap edit_post on {id}; attachment {id} must exist)# | The editable fields the app uses. |
| method | delete(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/media/{id:[\d]+} (cap delete_post on {id}; attachment {id} must exist)# | Attachments go to the trash only when MEDIA_TRASH (or rest_attachment_trashable) says so; force removes the row, its meta, and its files. |
Internals 7
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | restDate(string $value, string $param): string# | ||||
| private | storeWithPlugins(Minn\Media\Upload $upload, Minn\Http\Request $request, Closure $refused): array# | With plugins loaded, the file goes through the runtime's wp_handle_sideload (a raw body) or wp_handle_upload (a form field), as the reference's REST upload sends it: their prefilters, the allowed types (upload_mimes), the content check, the name, the move and wp_handle_upload, where SVG and security plugins work. A refusal is the engine's REST error with the runtime's words.
@return array{0: string, 1: string} the path relative to the uploads folder, and the type | |||
| private | insertedWithPlugins(string $relative, string $type, Minn\Media\Upload $upload, Minn\Http\Request $request): Minn\Http\Response# | With plugins loaded, the attachment saved as the reference's controller saves it (probe rest-media-save): the photo's own title and caption (wp_read_image_metadata) unless the request names them, the prepared attachment through rest_pre_insert_attachment, the file's name as the title when none is left, then wp_insert_attachment, the REST actions (the alt text between them), wp_after_insert_post, and the sizes. | |||
| private | preparedAttachment(stdClass $attachment, array $params, Minn\Http\Request $request): array# | rest_block_hooks_post_types, then rest_pre_insert_attachment, over the prepared attachment, then the caption and description the request sends.
@return array<string, mixed> | |||
| private | finishedWithPlugins(int $id, array $params, Minn\Http\Request $request, ?Minn\Content\PostRecord $before): void# | After rest_insert_attachment: the alt text, rest_after_insert_attachment and wp_after_insert_post, in the reference's order.
| |||
| private | params(Minn\Http\Request $request): array# | The fields a media request sends, wherever it sends them: the query, a form, or a JSON body. @return array<string, mixed> | |||
| private | attachment(int $id): Minn\Content\PostRecord# |
Nothing matches.