API / Minn\Rest / PostsController

PostsController final readonly class

Minn\Rest\PostsController · public/minn/src/Minn/Rest/PostsController.php · 197 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): 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.

$shape(\Closure(PostRecord, Context): array<string, mixed>)|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): Minn\Http\Response#

One post of any type, with the reference's read rules.

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 3

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

privatetotals(WP_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(WP_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): void#

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.