class User

User authentication and authorization.

Traits

Strict class for better experience.

Constants

MANUAL

INACTIVITY

Properties

string $guestRole
string $authenticatedRole
callable[] $onLoggedIn
callable[] $onLoggedOut
IAuthenticator $authenticator
IAuthorizator $authorizator

Methods

__construct(IUserStorage $storage, IAuthenticator $authenticator = null, IAuthorizator $authorizator = null)

No description

getStorage()

No description

void
login($user, string $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.

mixed
getId()

Returns current user ID, if any.

setAuthenticator(IAuthenticator $handler)

Sets authentication handler.

IAuthenticator|null
getAuthenticator()

Returns authentication handler.

IAuthenticator|null
getAuthenticatorIfExists()

Returns authentication handler.

bool
hasAuthenticator() deprecated

No description

setExpiration(string|null $expire, int $flags = 0)

Enables log out after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.

int|null
getLogoutReason()

Why was user logged out?

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 = IAuthorizator::ALL, $privilege = IAuthorizator::ALL)

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

setAuthorizator(IAuthorizator $handler)

Sets authorization handler.

IAuthorizator|null
getAuthorizator()

Returns current authorization handler.

IAuthorizator|null
getAuthorizatorIfExists()

Returns current authorization handler.

bool
hasAuthorizator() deprecated

No description

Details

at line 63
__construct(IUserStorage $storage, IAuthenticator $authenticator = null, IAuthorizator $authorizator = null)

Parameters

IUserStorage $storage
IAuthenticator $authenticator
IAuthorizator $authorizator

at line 71
final IUserStorage getStorage()

Return Value

IUserStorage

at line 85
void login($user, string $password = null)

Conducts the authentication process. Parameters are optional.

Parameters

$user
string $password

Return Value

void

Exceptions

AuthenticationException if authentication was not successful

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

Logs out the user from the current session.

Parameters

bool $clearIdentity

Return Value

void

at line 119
final bool isLoggedIn()

Is this user authenticated?

Return Value

bool

at line 131
final IIdentity|null getIdentity()

Returns current user identity, if any.

Return Value

IIdentity|null

at line 144
mixed getId()

Returns current user ID, if any.

Return Value

mixed

at line 155
User setAuthenticator(IAuthenticator $handler)

Sets authentication handler.

Parameters

IAuthenticator $handler

Return Value

User

at line 165
final IAuthenticator|null getAuthenticator()

Returns authentication handler.

Return Value

IAuthenticator|null

at line 181
final IAuthenticator|null getAuthenticatorIfExists()

Returns authentication handler.

Return Value

IAuthenticator|null

at line 188
final bool hasAuthenticator() deprecated

deprecated

Return Value

bool

at line 200
User setExpiration(string|null $expire, int $flags = 0)

Enables log out after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.

Parameters

string|null $expire
int $flags

Return Value

User

at line 221
final int|null getLogoutReason()

Why was user logged out?

Return Value

int|null

at line 233
array getRoles()

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

Return Value

array

at line 247
final bool isInRole(string $role)

Is a user in the specified effective role?

Parameters

string $role

Return Value

bool

at line 257
bool isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthorizator::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 273
User setAuthorizator(IAuthorizator $handler)

Sets authorization handler.

Parameters

IAuthorizator $handler

Return Value

User

at line 283
final IAuthorizator|null getAuthorizator()

Returns current authorization handler.

Return Value

IAuthorizator|null

at line 299
final IAuthorizator|null getAuthorizatorIfExists()

Returns current authorization handler.

Return Value

IAuthorizator|null

at line 306
final bool hasAuthorizator() deprecated

deprecated

Return Value

bool