Documentation

User extends AuthenticationObject
in package
Uses Permission, RetrievalTrait, HandleTrait

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()  : User|null
Create a new user This will insert the user into the database and return the created user 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>
byEmail()  : User|null
Get a user by their email address
byGroup()  : 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
byNotVerified()  : array<string|int, User>
Get a list of users who were not verified as of the $since DateTime
byOrganization()  : array<string|int, mixed>
byRole()  : array<string|int, User>
Get a list of users by a specific role
checkInstance()  : mixed
clearFields()  : void
clearSessions()  : void
Clear all sessions of the user
email()  : string
Get the user's email from the cache
getAll()  : array<string|int, mixed>
getField()  : mixed
getGroups()  : array<string|int, Group>
Get the user's groups
getPermissions()  : array<string|int, string>
Get the user's permissions including those inherited from roles
getRoles()  : array<string|int, Role>
Get the user's roles
getUserPermissions()  : array<string|int, string>
Get the user's permissions
groupsAdd()  : void
Add Groups to the user This will add the groups automatically into the database
groupsRemove()  : void
Remove groups from the user This will remove the groups automatically from the database
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
isVerified()  : bool
Check if a User is verified
loadObject()  : void
Re-/Loads the user object
nullId()  : mixed
organization()  : Organization|null
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
refreshAllPermissions()  : void
Reset the permissions cache
refreshPermissions()  : void
Reset the permissions cache
remove()  : void
Deactivate this user
rolesAdd()  : void
Add roles to the user This will add the roles automatically into the database
rolesRemove()  : void
Remove roles from the user This will remove the roles automatically from the database
updateEmail()  : void
Update the email address of the user This will update the email in the database
updateOrganization()  : void
updatePassword()  : void
Update the password of the user This will update the password in the database
verified()  : null|string
Get the users` verified date
verify()  : void
Verify the User
verifyPassword()  : bool
Verify a plaintext password against this user's stored credential and, on a correct match, transparently upgrade the stored hash when it is stale (rehash-on-login / onion peel). Self-healing.
setField()  : void

Properties

$dbExpression

public static array<string|int, mixed> $dbExpression = []

$dbPermissionsObjectColumn

public static string $dbPermissionsObjectColumn = "user"

$dbPermissionsTable

public static string $dbPermissionsTable = "z_user_permission"

$dbTable

public static string $dbTable = "z_user"

$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 user This will insert the user into the database and return the created user object

public static add(string $email, string|null $password[, DateTime|null $verified = null ]) : User|null
Parameters
$email : string

The email of the new user

$password : string|null

Optional the password of the new user (plain text, will be hashed)

$verified : DateTime|null = null

Optional datetime object indicating when the user was verified

Return values
User|null —

The created user object or null on failure

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> —

byEmail()

Get a user by their email address

public static byEmail(string $email) : User|null
Parameters
$email : string

The email address of the user

Return values
User|null —

The User object if found, null otherwise

byGroup()

public static byGroup(Group $group) : array<string|int, mixed>
Parameters
$group : Group
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

byNotVerified()

Get a list of users who were not verified as of the $since DateTime

public static byNotVerified(DateTime $since) : array<string|int, User>
Parameters
$since : DateTime

When to check for non-verified users

Return values
array<string|int, User> —

array of user objects

byOrganization()

public static byOrganization(Organization $organization) : array<string|int, mixed>
Parameters
$organization : Organization
Return values
array<string|int, mixed> —

byRole()

Get a list of users by a specific role

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

The role to filter users by

Return values
array<string|int, User> —

An array of User objects associated with the specified role

clearSessions()

Clear all sessions of the user

public clearSessions() : void
Return values
void —

email()

Get the user's email from the cache

public email() : string
Return values
string —

The email of the 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 —

getGroups()

Get the user's groups

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

Array of group objects

getPermissions()

Get the user's permissions including those inherited from roles

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

Array of permissions

getRoles()

Get the user's roles

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

Array of role objects

getUserPermissions()

Get the user's permissions

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

Array of permissions

groupsAdd()

Add Groups to the user This will add the groups automatically into the database

public groupsAdd(array<string|int, Group> ...$groups) : void
Parameters
$groups : array<string|int, Group>

The groups to add to the user

Return values
void —

groupsRemove()

Remove groups from the user This will remove the groups automatically from the database

public groupsRemove(array<string|int, Group> ...$groups) : void
Parameters
$groups : array<string|int, Group>

The groups to remove from the user

Return values
void —

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

isVerified()

Check if a User is verified

public isVerified([string $at = "NOW" ]) : bool
Parameters
$at : string = "NOW"

When to check verification status (default: "NOW")

Return values
bool —

Returns true if the user is verified at the specified time, false otherwise

loadObject()

Re-/Loads the user object

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

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

Return values
void —

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 —

refreshAllPermissions()

Reset the permissions cache

public refreshAllPermissions() : void
Return values
void —

refreshPermissions()

Reset the permissions cache

public refreshPermissions() : void
Return values
void —

remove()

Deactivate this user

public remove() : void
Return values
void —

rolesAdd()

Add roles to the user This will add the roles automatically into the database

public rolesAdd(array<string|int, Role> ...$roles) : void
Parameters
$roles : array<string|int, Role>

The roles to add to the user

Return values
void —

rolesRemove()

Remove roles from the user This will remove the roles automatically from the database

public rolesRemove(array<string|int, Role> ...$roles) : void
Parameters
$roles : array<string|int, Role>

The roles to remove from the user

Return values
void —

updateEmail()

Update the email address of the user This will update the email in the database

public updateEmail(string $email) : void
Parameters
$email : string

The new email address

Return values
void —

updateOrganization()

public updateOrganization(Organization|null $organization) : void
Parameters
$organization : Organization|null
Return values
void —

updatePassword()

Update the password of the user This will update the password in the database

public updatePassword(string $password) : void
Parameters
$password : string

The new password

Return values
void —

verified()

Get the users` verified date

public verified() : null|string
Return values
null|string —

The users verified date or null if not verified

verify()

Verify the User

public verify([DateTime|null $date = null ]) : void
Parameters
$date : DateTime|null = null

Optional datetime object indicating when the user was verified. If null, current time will be used.

Return values
void —

verifyPassword()

Verify a plaintext password against this user's stored credential and, on a correct match, transparently upgrade the stored hash when it is stale (rehash-on-login / onion peel). Self-healing.

public verifyPassword(string $password) : bool

This is the password-check entry point for logging a user in.

Parameters
$password : string

The plaintext password to check

Return values
bool —

Whether the password matched

setField()

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

Search results