Actor
in package
implements
JsonSerializable
Read onlyYes
FinalYes
An "Actor" transports information about whose authority is being claimed to perform an operation.
Actors consist of two information:
- The principal whose authority is being claimed to perform an operation. Permissions are checked against the principal.
- If someone else performs the operation on the principal's behalf, that party as the delegate, e.g. a bot or a background job acting for a user. The delegate is kept for auditing and never adds permissions.
Creating an Actor asserts nothing. Callers check whether the operation is permitted before creating it. Consumers receiving an Actor from another app, a job payload or a request, check the principal's permissions themselves.
Examples
// 1. User acting as themselves
$actor = Actor::of(Principal::user('alice'));
// 2. User impersonating another user
$actor = Actor::of(Principal::user('alice'))
->onBehalfOf(Principal::user('bob'));
// 3. Bot acting on behalf of a user
$actor = Actor::of(Principal::bot('summarizer', 'assistant'))
->onBehalfOf(Principal::user('alice'));
// 4. System component acting as the system itself - e.g. a cron job
$actor = Actor::of(Principal::system('sync', 'calendar'));
// 5. System component acting on behalf of a user
$actor = Actor::of(Principal::system('retention', 'files_versions'))
->onBehalfOf(Principal::user('alice'));
// 6. A federated user acting as itself
$actor = Actor::of(Principal::user('bob', 'cloud.example'));
// 7. A public visitor acting as itself
$actor = Actor::of(Principal::anonymous('public-share-token', 'files_sharing:visitor'));
Tags
Attributes
- #[Consumable]
- $since: '36.0.0'
Table of Contents
Interfaces
- JsonSerializable
Properties
- $delegate : Principal|null
- $principal : Principal
Methods
- equals() : bool
- fromArray() : self
- Rehydrate from a serialized payload.
- isDelegated() : bool
- jsonSerialize() : PrincipalData}
- Serialize the Actor to an array.
- key() : string
- Get a unique key for the Actor.
- of() : self
- Actor with no delegation.
- onBehalfOf() : self
- $this acts as $target with the target's full view.
- __construct() : mixed
- assertValidActorData() : void
- The principal is validated by Principal::fromArray.
Properties
$delegate
public
Principal|null
$delegate
= null
$principal
public
Principal
$principal
Methods
equals()
public
equals(self $other) : bool
Parameters
- $other : self
Tags
Return values
boolfromArray()
Rehydrate from a serialized payload.
public
static fromArray(array<string, mixed> $data) : self
Parameters
- $data : array<string, mixed>
-
- see
Actor::jsonSerialize
- see
Tags
Return values
selfisDelegated()
public
isDelegated() : bool
Tags
Return values
booljsonSerialize()
Serialize the Actor to an array.
public
jsonSerialize() : PrincipalData}
Tags
Attributes
- #[Override]
Return values
PrincipalData}key()
Get a unique key for the Actor.
public
key() : string
Tags
Return values
stringof()
Actor with no delegation.
public
static of(Principal $principal) : self
Parameters
- $principal : Principal
Tags
Return values
selfonBehalfOf()
$this acts as $target with the target's full view.
public
onBehalfOf(Principal $target) : self
The returned actor has $target as principal and this actor's principal as delegate.
Parameters
- $target : Principal
Tags
Return values
self__construct()
private
__construct(Principal $principal[, Principal|null $delegate = null ]) : mixed
Parameters
assertValidActorData()
The principal is validated by Principal::fromArray.
private
static assertValidActorData(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>