Documentation

Group extends Role
in package

Table of Contents

$dbExpression  : array<string|int, mixed>
$dbPermissionsObjectColumn  : string
$dbPermissionsTable  : string
$dbTable  : string
$data  : array<string|int, mixed>|null
$permissionChanged  : bool
Process-wide flag indicating that permission-related data has changed.
$id  : int|null
__construct()  : mixed
add()  : Role
Create a new Role This will insert the role into the database and return the created Role object
all()  : array<string|int, object>
Get a list of permission objects (user or role)
buildPermissionVariants()  : array<string|int, string>
Build permission variants for a given permission name
byAccessToAll()  : array<string|int, mixed>
byAccessToAnyOf()  : array<string|int, mixed>
byId()  : object|null
Get a permission object (user or role) by its id
byIds()  : array<string|int, object>
Get a list of permission objects (user or role) by their ids
byName()  : Role|null
Get a Role by its name
byUser()  : array<string|int, Role>
Get a list of Roles by User
checkInstance()  : mixed
clearFields()  : void
getAll()  : array<string|int, mixed>
getField()  : mixed
getPermissions()  : array<string|int, string>
Get Permissions which are associated with this Role
getUsers()  : array<string|int, User>
Get Users with this Role
hasAccessAll()  : bool
Check if the permission object (user or role) has all of the given permissions
hasAccessAnyOf()  : bool
Check if the permission object (user or role) has one of the permissions
id()  : mixed
loadObject()  : void
Re-/Loads the Role Object
name()  : string
Get the Roles name from the cache
nullId()  : mixed
permissionsAdd()  : void
Add permissions to an permission object (user or role)
permissionsRemove()  : void
Remove permissions from the permission object (user or role)
refresh()  : void
Refresh the current permission object (user or role) by clearing all its fields and setting them new
refreshPermissions()  : void
Reset the Permissions Cache
remove()  : void
Remove the Role This will deactivate the Role in the Database
setPermissionsByRole()  : void
Replace this Role's permissions with the permissions of another Role.
update()  : void
Rename the Role
setField()  : void
refreshUsers()  : void
Reset the Users Cache

Properties

$dbExpression

public static array<string|int, mixed> $dbExpression = ["zr.is_group" => 1]

$dbPermissionsObjectColumn

public static string $dbPermissionsObjectColumn = "role"

$dbPermissionsTable

public static string $dbPermissionsTable = "z_role_permission"

$dbTable

public static string $dbTable = "z_role"

$data

protected array<string|int, mixed>|null $data = null

The data of the authentication object

$permissionChanged

Process-wide flag indicating that permission-related data has changed.

protected static bool $permissionChanged = false

Declared once on the base class (and never redeclared in the trait or subclasses) so that User, Role and Group all share a single storage slot. When true, cached permissions are reloaded on each access, regardless of which authentication object triggered the change.

Methods

__construct()

public __construct(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>
Return values
mixed —

add()

Create a new Role This will insert the role into the database and return the created Role object

public static add(string $rolename) : Role
Parameters
$rolename : string

The name of the new role

Return values
Role —

The created Role object

all()

Get a list of permission objects (user or role)

public static all() : array<string|int, object>
Return values
array<string|int, object> —

buildPermissionVariants()

Build permission variants for a given permission name

public static buildPermissionVariants(string $permissionName) : array<string|int, string>

e.g. "edit.article" => [".", "edit.", "edit.article.", "edit.article"]

Parameters
$permissionName : string

The permission name to build variants for

Return values
array<string|int, string> —

An array of permission variants

byAccessToAll()

public static byAccessToAll(string ...$permissionNames) : array<string|int, mixed>
Parameters
$permissionNames : string
Return values
array<string|int, mixed> —

byAccessToAnyOf()

public static byAccessToAnyOf(string ...$permissionNames) : array<string|int, mixed>
Parameters
$permissionNames : string
Return values
array<string|int, mixed> —

byId()

Get a permission object (user or role) by its id

public static byId(int|string $id) : object|null
Parameters
$id : int|string

the id of the object

Return values
object|null —

the permission object if found, null otherwise

byIds()

Get a list of permission objects (user or role) by their ids

public static byIds(int ...$ids) : array<string|int, object>
Parameters
$ids : int

The ids of the objects to retrieve

Return values
array<string|int, object> —

The list of permission objects

byName()

Get a Role by its name

public static byName(string $name) : Role|null
Parameters
$name : string

The name of the role

Return values
Role|null —

The Role object if found, null otherwise

byUser()

Get a list of Roles by User

public static byUser(User $user) : array<string|int, Role>
Parameters
$user : User

The user to filter roles by

Return values
array<string|int, Role> —

An array of Role objects associated with the specified user

getAll()

public getAll() : array<string|int, mixed>
Return values
array<string|int, mixed> —

getField()

public getField(string $field) : mixed
Parameters
$field : string
Return values
mixed —

getPermissions()

Get Permissions which are associated with this Role

public getPermissions() : array<string|int, string>
Return values
array<string|int, string> —

The permissions associated with this role

getUsers()

Get Users with this Role

public getUsers() : array<string|int, User>
Return values
array<string|int, User> —

The users with this role

hasAccessAll()

Check if the permission object (user or role) has all of the given permissions

public hasAccessAll(array<string|int, string> ...$permissionNames) : bool
Parameters
$permissionNames : array<string|int, string>

The names of the permissions to check

Return values
bool —

True if the object has all of the permissions, false otherwise

hasAccessAnyOf()

Check if the permission object (user or role) has one of the permissions

public hasAccessAnyOf(array<string|int, string> ...$permissionNames) : bool
Parameters
$permissionNames : array<string|int, string>

The names of the permissions to check

Return values
bool —

True if the object has at least one of the permissions, false otherwise

loadObject()

Re-/Loads the Role Object

public loadObject(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

The data to load into the Role object (in the format of a database row)

Return values
void —

name()

Get the Roles name from the cache

public name() : string
Return values
string —

The name of the Role

permissionsAdd()

Add permissions to an permission object (user or role)

public permissionsAdd(array<string|int, string> ...$permissionNames) : void
Parameters
$permissionNames : array<string|int, string>

The names of the permissions to add

Return values
void —

permissionsRemove()

Remove permissions from the permission object (user or role)

public permissionsRemove(array<string|int, string> ...$permissionNames) : void
Parameters
$permissionNames : array<string|int, string>

The names of the permissions to remove

Return values
void —

refresh()

Refresh the current permission object (user or role) by clearing all its fields and setting them new

public refresh() : void
Tags
throws
RuntimeException

If the object no longer exists

Return values
void —

refreshPermissions()

Reset the Permissions Cache

public refreshPermissions() : void
Return values
void —

remove()

Remove the Role This will deactivate the Role in the Database

public remove() : void
Return values
void —

setPermissionsByRole()

Replace this Role's permissions with the permissions of another Role.

public setPermissionsByRole(Role $role) : void

Removes all currently assigned permissions and copies the source Role's permissions over.

Parameters
$role : Role

The role whose permissions should be adopted

Return values
void —

update()

Rename the Role

public update(string $newName) : void
Parameters
$newName : string

The new name for the role

Return values
void —

setField()

protected setField(string $field, mixed $value) : void
Parameters
$field : string
$value : mixed
Return values
void —

refreshUsers()

Reset the Users Cache

private refreshUsers() : void
Return values
void —

Search results