API / Minn\Rest / PostsController

PostsController final readonly class

Minn\Rest\PostsController · public/minn/src/Minn/Rest/PostsController.php · 264 lines

wp/v2 posts and pages, read side.

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Rest\PostObject $object

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Rest\PostObject $object, Minn\Rest\Caller $caller)#
methodlist(Minn\Http\Request $request, string $base): Minn\Http\ResponseGET /wp/v2/{base:posts} (public)GET /wp/v2/{base:pages} (public)#

The posts or pages list.

methodserveList(Minn\Http\Request $request, string $type, ?Closure $shape = NULL, ?Closure $readable = NULL, ?array $registered = NULL): Minn\Http\Response#

The list for any post type as the reference serves it (probe rest-post-lists): the caller and the statuses judged, the request's parameters sanitized, the query arguments through rest_{type}_query and rest_query_var-*, a WP_Query (so pre_get_posts and every query filter run), then each post the caller may read (or edit, in the edit context) shaped (by $shape when the type has its own object, as media does). The totals are the query's, counted again without the page when a later page came back empty. A media search also matches file names, as the reference's does. A type whose posts are read by a rule of its own names it ($readable, by post id: a pattern needs read_post, published or not), its rows still counted; a type whose list takes parameters of its own names them ($registered, as menu items do); a shape that answers null leaves the post out.

$shape(\Closure(PostRecord, Context): ?array<string, mixed>)|null
$readable(\Closure(int): bool)|null
$registeredarray<string, array<string, mixed>>|null
staticrequestedStatuses(Minn\Http\Request $request): ?array#

The statuses a list request names, null when it names none: a list given as one (status[]=draft), its members that are not plain values dropped, or a comma-separated string.

@return list<string>|null
methodsingle(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponseGET /wp/v2/{base:posts|pages}/{id:[\d]+} (public; post {id} must exist; edit context: cap edit_post on {id})#

One post or page.

methodserveSingle(Minn\Http\Request $request, string $type, string $id, ?Closure $readable = NULL): Minn\Http\Response#

One post of any type, with the reference's read rules: the edit context for one who may edit it, then the password (any given that is not the post's own is refused, protected or not, before the post's readability is judged), then the read itself, by the type's own rule when it has one ($readable, by post id) and otherwise a published post or one the caller may read. The excerpt is cut to the excerpt_length asked for, and the right password opens the content and the excerpt.

$readable(\Closure(int): bool)|null
staticwithAlternate(Minn\Http\Response $response, Minn\Content\PostRecord $post): Minn\Http\Response#

A viewable type's single post points at its page on the site.

Internals 4

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

privateshaped(array $posts, Minn\Rest\Context $context, ?Minn\Rest\Fields $fields, ?Closure $shape, ?Closure $readable): array#

A list's posts as objects: each the caller may read (or edit, in the edit context), shaped by the type's own shape or the post object.

$postsarray<array-key, mixed>
$shape(\Closure(PostRecord, Context): ?array<string, mixed>)|null
$readable(\Closure(int): bool)|null
@return list<array<string, mixed>>
privatetotals(Minn\Objects\Query $query, array $vars): array#

The total and the page count: the query's own, or, when a later page came back with nothing counted, a count without the page. A page past the last is refused.

$varsarray<string, mixed>
@return array{0: int, 1: int}
privatereadable(Minn\Objects\Post $post): bool#

Whether the caller may read a post: published, readable to them, a public status, or an attachment of one they may.

privatevisibleStatuses(Minn\Http\Request $request, string $type, Minn\Rest\Context $context): array#

The statuses this caller may list. Public callers see only 'publish'; any other status and the edit context need a caller who can edit this type, and a status beyond publish is a parameter error without that cap. Answers the statuses the list reads, publish (or inherit) when none is named.

@return list<string>