Permission
A single authorization capability, addressed by the canonical key `{namespace}.{resource}:{action}` (namespace optional). It is the atom of the permissions matrix: roles group these, the resolver grants them, and `can()` checks them. Value identity is the key alone — {@see self::$metadata} is non-authoritative. Immutable by construction.
Permission::__construct()
public function __construct(string $resource, string $action, ?string $namespace = null, array $metadata = []):Parameters
| Name | Type | Description |
|---|---|---|
| $resource | string | |
| $action | string | |
| $namespace | ?string | |
| $metadata | array<string, mixed> | non-authoritative extra detail; excluded from key()/equals() |
Permission::key()
public function key(): stringThe canonical string: `{namespace}.{resource}:{action}`, or `{resource}:{action}` when namespace is null.
Permission::of()
public static function of(string $resource, string $action, ?string $namespace = null): selfBuilds a Permission straight from its segments, without parsing a key string.
Parameters
| Name | Type | Description |
|---|---|---|
| $resource | string | |
| $action | string | |
| $namespace | ?string |
Permission::parse()
public static function parse(string $key): selfParses a canonical key. `action` is everything after the single `:`; of the pre-colon part, the segment after the last `.` is the resource and the rest is the namespace (null if no `.`). A key with no `:`, an empty segment, or more than one `:` is malformed — fail-closed.
Parameters
| Name | Type | Description |
|---|---|---|
| $key | string |
Throws
\InvalidArgumentException on a malformed key
Permission::equals()
public function equals(self $other): boolValue equality by canonical key (metadata is not part of identity).
Parameters
| Name | Type | Description |
|---|---|---|
| $other | self |