API / Minn\Http / Policy

Policy final readonly class

Minn\Http\Policy · public/minn/src/Minn/Http/Policy.php · 115 lines

What a route requires of its caller, as data on the route: the router enforces it before the handler runs, so a grep over the attributes is the authorization surface. The two refusals are the reference's: a caller who is not signed in gets the sign-in code (401), a signed-in caller who lacks the capability gets the refusal code (403); how a bad nonce is answered belongs to whoever judges the policy. A policy that names a subject has the record looked up first, and answers the record's 404 before either refusal, which is the reference's order.

Written inline in the attribute with `new`, which is what an attribute argument allows: `policy: new Policy(Access::Cap, 'upload_files', refuse: 'rest_cannot_create', message: '...')`.

Constants and properties

propreadonly Minn\Http\Access $access

Promoted from the constructor.

propreadonly ?string $cap

Promoted from the constructor.

propreadonly array $caps

Promoted from the constructor.

propreadonly ?string $param

Promoted from the constructor.

propreadonly string $signIn

Promoted from the constructor.

propreadonly string $signInMessage

Promoted from the constructor.

propreadonly string $refuse

Promoted from the constructor.

propreadonly string $message

Promoted from the constructor.

propreadonly ?Minn\Http\Policy $edit

Promoted from the constructor.

propreadonly ?Minn\Http\Subject $subject

Promoted from the constructor.

propreadonly ?string $missing

Promoted from the constructor.

propreadonly ?string $missingMessage

Promoted from the constructor.

propreadonly int $signInStatus

Promoted from the constructor.

propreadonly ?string $verb

Promoted from the constructor.

propreadonly ?array $opener

Promoted from the constructor.

Public

new__construct(Minn\Http\Access $access = Minn\Http\Access::Public, ?string $cap = NULL, array $caps = array ( ), ?string $param = NULL, string $signIn = 'rest_not_logged_in', string $signInMessage = 'You are not currently logged in.', string $refuse = 'rest_forbidden', string $message = 'Sorry, you are not allowed to do that.', ?Minn\Http\Policy $edit = NULL, ?Minn\Http\Subject $subject = NULL, ?string $missing = NULL, ?string $missingMessage = NULL, int $signInStatus = 401, ?string $verb = NULL, ?array $opener = NULL)#
$capslist<string>further capabilities every one of which the caller must hold
$paramstring|nullthe pattern capture holding the object id an Own policy judges, or the subject's id
$editPolicy|nulla policy judged as well when the request asks for the edit context
$subjectSubject|nullthe record the capture names, looked up before the caller is judged
$missingstring|nullthe 404 code when the subject does not exist; the subject's own when null
$missingMessagestring|nullits message; the subject's own when null
$signInStatusintthe status a signed-out caller is refused with (the reference answers some routes' signed-out writes 404, not 401)
$verbstring|nullwhat a Type or Taxonomy route does (create, edit, delete), judged with the type's or taxonomy's own capabilities
methodisPublic(): bool#

Whether the route is open to anyone with nothing to look up, so the gate need not run at all.

methodmissingCode(): string#

The 404 code a missing subject earns.

methodmissingText(): string#

The 404 message a missing subject earns.

methodcapabilities(): array#

Every capability the policy asks for by name, the one on the object included, so a listing can show what a route takes.

@return list<string>
methodtoArray(): array#

The policy as data, for the route catalogue. @return array<string, mixed>

@return array<string, mixed>
methoddescribe(): string#

The policy in one line, for the route index and the docs.