Nextcloud PHP API (master)

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:

  1. The principal whose authority is being claimed to perform an operation. Permissions are checked against the principal.
  2. 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
psalm-import-type

PrincipalData from Principal

psalm-immutable
since
36.0.0
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

Methods

equals()

public equals(self $other) : bool
Parameters
$other : self
Tags
since
36.0.0
Return values
bool

fromArray()

Rehydrate from a serialized payload.

public static fromArray(array<string, mixed> $data) : self
Parameters
$data : array<string, mixed>
  • see Actor::jsonSerialize
Tags
throws
InvalidArgumentException
  • if the data is invalid
since
36.0.0
Return values
self

isDelegated()

public isDelegated() : bool
Tags
since
36.0.0
Return values
bool

jsonSerialize()

Serialize the Actor to an array.

public jsonSerialize() : PrincipalData}
Tags
since
36.0.0
Attributes
#[Override]
Return values
PrincipalData}

key()

Get a unique key for the Actor.

public key() : string
Tags
since
36.0.0
Return values
string

of()

Actor with no delegation.

public static of(Principal $principal) : self
Parameters
$principal : Principal
Tags
since
36.0.0
Return values
self

onBehalfOf()

$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
throws
InvalidArgumentException
  • if the target is this actor's own principal
LogicException
  • if this actor already acts on behalf of another principal
since
36.0.0
Return values
self

assertValidActorData()

The principal is validated by Principal::fromArray.

private static assertValidActorData(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
psalm-assert

array{principal: array<string, mixed>, delegate?: ?array<string, mixed>} $data

throws
InvalidArgumentException

-- if the data is invalid

On this page

Search results