API / Minn\Rest / Caller

Caller final class

Minn\Rest\Caller · public/minn/src/Minn/Rest/Caller.php · 149 lines

Who is making this REST call. Resolved once from the cookie and nonce; an anonymous or failed caller has id 0 and every capability check fails.

Constants and properties

privateMinn\Auth\Authenticated|Minn\Auth\AuthFailure|null $resolved
privatereadonly Minn\Http\Request $request

Promoted from the constructor.

privatereadonly Minn\Auth\Authenticator $authenticator

Promoted from the constructor.

privatereadonly Minn\Auth\Capabilities $capabilities

Promoted from the constructor.

Public

new__construct(Minn\Http\Request $request, Minn\Auth\Authenticator $authenticator, Minn\Auth\Capabilities $capabilities)#
methodresolveAs(Minn\Auth\Authenticated $session): void#

Settles the caller as a session already proven elsewhere: an in-process request a plugin makes through rest_do_request() carries no nonce, so it runs as whoever the outer request resolved.

methodresolveAnonymous(): void#

Settles the caller as nobody: plugin code (determine_current_user) signed the request out.

methodcookieBound(): bool#

Whether a sign-in cookie vouches for this caller (or failed to, for want of its nonce): a cookie's nonce vouches for its own user only.

methodrecheck(): void#

Has the cookie and nonce checked again on the next question: a plugin's nonce lifetime (nonce_life) is heard only once plugins load.

methodresolveInvalidNonce(): void#

Settles the caller as one whose cookie's nonce does not vouch for the user plugin code named.

methodsession(): ?Minn\Auth\Authenticated#

The session, or null for an anonymous or refused caller.

methodid(): int#

The caller's user id, 0 when anonymous.

methodcan(string $capability, ?int $postId = NULL): bool#

Whether the caller holds a capability, on a post when given. With plugins loaded the answer is WordPress's: the same mapping, then map_meta_cap and user_has_cap, where role editors and lock plugins have their say.

methodeditsAnyRestType(): bool#

Whether the caller can edit posts of some type shown in REST: what the reference asks before showing statuses, block types and the active theme. A plugin's types count once plugins are loaded.

methodcapabilities(): Minn\Auth\Capabilities#

The capability engine.

methodrequire(string $code = 'rest_not_logged_in', string $message = 'You are not currently logged in.', int $status = 401): Minn\Auth\Authenticated#

The session, or the reference's refusal: a bad nonce is always 403 rest_cookie_invalid_nonce; no identity is the caller-supplied error.

methodrequireFloor(string ...$capabilities): int#

The floor every Minn Admin route shares: a signed-in caller who can edit posts, plus any further capability named, all refused with the same rest_forbidden the reference uses. Returns the caller's id.

methodrequireCap(string ...$capabilities): void#

403 rest_forbidden unless the caller holds every capability named.

methodrefuse(string $code, string $message): Minn\RestError#

401 for an anonymous caller, 403 for one who is signed in but refused.

Internals 1

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

privateresolve(): Minn\Auth\Authenticated|Minn\Auth\AuthFailure#