class Role (View source)

A role. These roles can be structured in a tree.

Constants

private ROLE_IDENTIFIER_PATTERN

Properties

protected string $identifier

The identifier of this role

protected string $name

The name of this role (without package key)

protected string $packageKey

The package key this role belongs to (extracted from the identifier)

protected bool $abstract

Whether or not the role is "abstract", meaning it can't be assigned to accounts directly but only serves as a "template role" for other roles to inherit from

protected string $label

A human readable label for this role

protected string $description

A description for this role

protected Role[] $parentRoles
protected PrivilegeInterface[] $privileges

Methods

__construct(string $identifier, array $parentRoles = [], string $label = '', string $description = '')

No description

string
getIdentifier()

Returns the fully qualified identifier of this role

string
getPackageKey()

The key of the package that defines this role.

string
getName()

The name of this role, being the identifier without the package key.

void
setAbstract(bool $abstract)

No description

bool
isAbstract()

Whether or not this role is "abstract", meaning it can't be assigned to accounts directly but only serves as a "template role" for other roles to inherit from

void
setParentRoles(array $parentRoles)

Assign parent roles to this role.

array
getParentRoles()

Returns an array of all directly assigned parent roles.

array
getAllParentRoles()

Returns all (directly and indirectly reachable) parent roles for the given role.

void
addParentRole(Role $parentRole)

Add a (direct) parent role to this role.

bool
hasParentRole(Role $role)

Returns true if the given role is a directly assigned parent of this role.

void
setPrivileges(array $privileges)

Assign privileges to this role.

array
getPrivileges()

No description

array
getPrivilegesByType(string $className)

No description

PrivilegeInterface|null
getPrivilegeForTarget(string $privilegeTargetIdentifier, array $privilegeParameters = [])

No description

void
addPrivilege(PrivilegeInterface $privilege)

Add a privilege to this role.

string
__toString()

Returns the string representation of this role (the identifier)

string
getLabel()

No description

string
getDescription()

No description

Details

__construct(string $identifier, array $parentRoles = [], string $label = '', string $description = '')

No description

Parameters

string $identifier

The fully qualified identifier of this role (Vendor.Package:Role)

array $parentRoles
string $label

A label for this role

string $description

A description on this role

string getIdentifier()

Returns the fully qualified identifier of this role

Return Value

string

string getPackageKey()

The key of the package that defines this role.

Return Value

string

string getName()

The name of this role, being the identifier without the package key.

Return Value

string

void setAbstract(bool $abstract)

No description

Parameters

bool $abstract

Return Value

void

bool isAbstract()

Whether or not this role is "abstract", meaning it can't be assigned to accounts directly but only serves as a "template role" for other roles to inherit from

Return Value

bool

void setParentRoles(array $parentRoles)

Assign parent roles to this role.

Parameters

array $parentRoles

indexed by role identifier

Return Value

void

array getParentRoles()

Returns an array of all directly assigned parent roles.

Return Value

array

Array of direct parent roles, indexed by role identifier

array getAllParentRoles()

Returns all (directly and indirectly reachable) parent roles for the given role.

Return Value

array

Array of parent roles, indexed by role identifier

void addParentRole(Role $parentRole)

Add a (direct) parent role to this role.

Parameters

Role $parentRole

Return Value

void

bool hasParentRole(Role $role)

Returns true if the given role is a directly assigned parent of this role.

Parameters

Role $role

Return Value

bool

void setPrivileges(array $privileges)

Assign privileges to this role.

Parameters

array $privileges

Return Value

void

array getPrivileges()

No description

Return Value

array

Array of privileges assigned to this role

array getPrivilegesByType(string $className)

No description

Parameters

string $className

Fully qualified name of the Privilege class to filter for

Return Value

array

PrivilegeInterface|null getPrivilegeForTarget(string $privilegeTargetIdentifier, array $privilegeParameters = [])

No description

Parameters

string $privilegeTargetIdentifier
array $privilegeParameters

Return Value

PrivilegeInterface|null

the matching privilege or NULL if no privilege exists for the given constraints

void addPrivilege(PrivilegeInterface $privilege)

Add a privilege to this role.

Parameters

PrivilegeInterface $privilege

Return Value

void

string __toString()

Returns the string representation of this role (the identifier)

Return Value

string

the string representation of this role

string getLabel()

No description

Return Value

string

string getDescription()

No description

Return Value

string