class User

User authentication and authorization.

Constants

LogoutManual

Log-out reason

LogoutInactivity

Log-out reason

deprecated LOGOUT_MANUAL

deprecated MANUAL

deprecated LOGOUT_INACTIVITY

deprecated INACTIVITY

Properties

$guestRole

default role for unauthenticated user

$authenticatedRole

default role for authenticated user without own identity

$onLoggedIn
$onLoggedOut
bool $loggedIn
IIdentity $identity

Methods

__construct(UserStorage $storage, Authenticator|null $authenticator = null, Authorizator|null $authorizator = null)

No description

getStorage()

No description

void
login(IIdentity $user, string|null $password = null)

Conducts the authentication process. Parameters are optional.

void
logout(bool $clearIdentity = false)

Logs out the user from the current session.

bool
isLoggedIn()

Is this user authenticated?

IIdentity|null
getIdentity()

Returns current user identity, if any.

string|int|null
getId()

Returns current user ID, if any.

void
refreshStorage()

No description

setAuthenticator(Authenticator $handler)

Sets authentication handler.

getAuthenticator()

Returns authentication handler.

Authenticator|null
getAuthenticatorIfExists()

Returns authentication handler.

bool
hasAuthenticator() deprecated

No description

setExpiration(string|null $expire, bool $clearIdentity = false)

Enables log out after inactivity (like '20 minutes').

int|null
getLogoutReason()

Why was user logged out? Returns LOGOUT_MANUAL or LOGOUT_INACTIVITY.

array
getRoles()

Returns a list of effective roles that a user has been granted.

bool
isInRole(string $role)

Is a user in the specified effective role?

bool
isAllowed($resource = Authorizator::All, $privilege = Authorizator::All)

Has a user effective access to the Resource? If $resource is null, then the query applies to all resources.

setAuthorizator(Authorizator $handler)

Sets authorization handler.

getAuthorizator()

Returns current authorization handler.

Authorizator|null
getAuthorizatorIfExists()

Returns current authorization handler.

bool
hasAuthorizator() deprecated

No description

Details

at line 65
__construct(UserStorage $storage, Authenticator|null $authenticator = null, Authorizator|null $authorizator = null)

No description

Parameters

UserStorage $storage
Authenticator|null $authenticator
Authorizator|null $authorizator

at line 73
final UserStorage getStorage()

No description

Return Value

UserStorage

at line 87
void login(IIdentity $user, string|null $password = null)

Conducts the authentication process. Parameters are optional.

Parameters

IIdentity $user

name or Identity

string|null $password

Return Value

void

Exceptions

AuthenticationException

at line 115
final void logout(bool $clearIdentity = false)

Logs out the user from the current session.

Parameters

bool $clearIdentity

Return Value

void

at line 132
final bool isLoggedIn()

Is this user authenticated?

Return Value

bool

at line 145
final IIdentity|null getIdentity()

Returns current user identity, if any.

Return Value

IIdentity|null

at line 173
string|int|null getId()

Returns current user ID, if any.

Return Value

string|int|null

at line 180
final void refreshStorage()

No description

Return Value

void

at line 189
User setAuthenticator(Authenticator $handler)

Sets authentication handler.

Parameters

Authenticator $handler

Return Value

User

at line 199
final Authenticator getAuthenticator()

Returns authentication handler.

Return Value

Authenticator

at line 212
final Authenticator|null getAuthenticatorIfExists()

Returns authentication handler.

Return Value

Authenticator|null

at line 219
final bool hasAuthenticator() deprecated

deprecated

No description

Return Value

bool

at line 228
setExpiration(string|null $expire, bool $clearIdentity = false)

Enables log out after inactivity (like '20 minutes').

Parameters

string|null $expire
bool $clearIdentity

at line 238
final int|null getLogoutReason()

Why was user logged out? Returns LOGOUT_MANUAL or LOGOUT_INACTIVITY.

Return Value

int|null

at line 250
array getRoles()

Returns a list of effective roles that a user has been granted.

Return Value

array

at line 264
final bool isInRole(string $role)

Is a user in the specified effective role?

Parameters

string $role

Return Value

bool

at line 280
bool isAllowed($resource = Authorizator::All, $privilege = Authorizator::All)

Has a user effective access to the Resource? If $resource is null, then the query applies to all resources.

Parameters

$resource
$privilege

Return Value

bool

at line 295
User setAuthorizator(Authorizator $handler)

Sets authorization handler.

Parameters

Authorizator $handler

Return Value

User

at line 305
final Authorizator getAuthorizator()

Returns current authorization handler.

Return Value

Authorizator

at line 318
final Authorizator|null getAuthorizatorIfExists()

Returns current authorization handler.

Return Value

Authorizator|null

at line 325
final bool hasAuthorizator() deprecated

deprecated

No description

Return Value

bool

Traits

SmartObject