User
in package
The User class holds the user of the current request (user() helper, alias User), identified on construction by bearer token or the z_login_token cookie; not Permission\User
Table of Contents
- $execUserId : int
- $fields : array<string|int, mixed>
- $isLoggedIn : bool
- $orgId : int
- $userId : int
- $uuid : string|null
- $permissionsByUserCache : mixed
- $sessionToken : string|null
- __construct() : mixed
- checkPermission() : bool
- Checks if the effective user (not the sudo exec user) has a given permission, wildcards included ("*.*" or "edit.*" cover "edit.article"). Always false for anonymous users.
- checkPermissionOf() : bool
- checkSuperPermission() : bool
- getSessionToken() : string|null
- identify() : mixed
- Checks if the user is registered. Checks by the bearer token of the Authorization header, else by the z_login_token cookie.
- anonymousRequest() : mixed
Properties
$execUserId
public
int
$execUserId
= null
ID of the user that is logged in as this user.
Null represents an anonymous user
$fields
public
array<string|int, mixed>
$fields
= []
Holds the dataset from the database of this user
$isLoggedIn
public
bool
$isLoggedIn
= false
Holds if the user is logged in
$orgId
public
int
$orgId
= null
ID of the organization the user belongs to.
Null represents an user that does not belong to an organization, or an anonymous user.
Named $orgId rather than $organizationId (which is the column name) because this
property is read frequently in application code and the shorter name keeps call sites
tidy. The corresponding DB column is still organizationId.
$userId
public
int
$userId
= null
ID of the user in the database.
Null represents an anonymous user
$uuid
public
string|null
$uuid
= null
The UUID of the user.
$permissionsByUserCache
private
mixed
$permissionsByUserCache
= []
string[int] $permissionsByUserCache Array of permissions the user has, cached by user ID.
$sessionToken
private
string|null
$sessionToken
= null
The token used to authenticate the current session
Methods
__construct()
public
__construct() : mixed
Return values
mixed —checkPermission()
Checks if the effective user (not the sudo exec user) has a given permission, wildcards included ("*.*" or "edit.*" cover "edit.article"). Always false for anonymous users.
public
checkPermission(string $permission) : bool
Parameters
- $permission : string
-
Name of the permission
Return values
bool —True when the permission is given
checkPermissionOf()
public
checkPermissionOf(mixed $permission, int $userId) : bool
Parameters
- $permission : mixed
- $userId : int
Return values
bool —checkSuperPermission()
public
checkSuperPermission(mixed $permission) : bool
Parameters
- $permission : mixed
Return values
bool —getSessionToken()
public
getSessionToken() : string|null
Return values
string|null —identify()
Checks if the user is registered. Checks by the bearer token of the Authorization header, else by the z_login_token cookie.
public
identify() : mixed
Sets $isLoggedIn, $userId, $execUserId, $orgId, $fields, $uuid and the session token (nothing is returned). An expired session is invalidated in the database, a valid one gets its last use recorded.
Return values
mixed —anonymousRequest()
private
anonymousRequest() : mixed