Skip to content
docsv0.9.0

PermissionSet

The resolved authorization state for one request: the flat list of {@see GrantedPermission}s the resolver produced, plus the `'*'` superuser grant if the actor held it. Answers "can this actor do * X?" ({@see self::can()}) and "why?" ({@see self::sourcesOf()}). It may hold the same permission from more than one source (a role AND a flat scope) — that is what makes authorization explainable. Immutable by construction.

PermissionSet::__construct()

public function __construct(array $granted, bool $grantsAll = false, ?Milpa\Auth\PermissionSource $allSource = null):

Parameters

Parameters of __construct()
NameTypeDescription
$grantedlist<GrantedPermission>every permission granted, with its provenance
$grantsAllbooltrue when the actor holds the `'*'` scope (grants all)
$allSource?PermissionSourceprovenance of the `'*'` grant, when $grantsAll

PermissionSet::can()

public function can(string $resource, string $action, ?string $namespace = null): bool

Whether the actor can perform $action on $resource (optionally scoped to $namespace). See {@see self::allows()}.

Parameters

Parameters of can()
NameTypeDescription
$resourcestring
$actionstring
$namespace?string

PermissionSet::allows()

public function allows(Milpa\Auth\Permission $permission): bool

Whether $permission is granted — true if `'*'` was granted, else an exact key match. No glob.

Parameters

Parameters of allows()
NameTypeDescription
$permissionMilpa\Auth\Permission

PermissionSet::all()

public function all(): array

PermissionSet::sourcesOf()

public function sourcesOf(Milpa\Auth\Permission $permission): array

Every source that granted $permission (each path, not deduped), preceded by the `'*'` source when this set grants all. Empty when $permission is not granted.

Parameters

Parameters of sourcesOf()
NameTypeDescription
$permissionMilpa\Auth\Permission

PermissionSet::grantsAll()

public function grantsAll(): bool