class Role (View source)

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

Constants

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 Role[] $parentRoles
protected PrivilegeInterface[] $privileges

Methods

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

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.

Role[]
getParentRoles()

Returns an array of all directly assigned parent roles.

Role[]
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.

getPrivileges()

No description

getPrivilegesByType(string $className)

No description

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)

Details

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

No description

Parameters

string $identifier

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

array $parentRoles

Exceptions

InvalidArgumentException

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

Role[] getParentRoles()

Returns an array of all directly assigned parent roles.

Return Value

Role[]

Array of direct parent roles, indexed by role identifier

Role[] getAllParentRoles()

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

Return Value

Role[]

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

PrivilegeInterface[] getPrivileges()

No description

Return Value

PrivilegeInterface[]

Array of privileges assigned to this role

PrivilegeInterface[] getPrivilegesByType(string $className)

No description

Parameters

string $className

Fully qualified name of the Privilege class to filter for

Return Value

PrivilegeInterface[]

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

No description

Parameters

string $privilegeTargetIdentifier
array $privilegeParameters

Return Value

PrivilegeInterface

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