class User

User authentication and authorization.

Constants

deprecated MANUAL

deprecated INACTIVITY

deprecated BROWSER_CLOSED

Properties

string $guestRole
string $authenticatedRole
callable[] $onLoggedIn
callable[] $onLoggedOut
IAuthenticator $authenticator
IAuthorizator $authorizator
bool read-only $loggedIn
IIdentity read-only $identity
mixed read-only $id
array read-only $roles
int read-only $logoutReason

Methods

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

No description

getStorage()

No description

void
login($user, $password = null)

Conducts the authentication process. Parameters are optional.

void
logout($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.

getAuthenticator($throw = true)

Returns authentication handler.

setExpiration($time, $flags = null, $clearIdentity = false)

Enables log out after inactivity.

int|null
getLogoutReason()

Why was user logged out?

array
getRoles()

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

bool
isInRole($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.

getAuthorizator($throw = true)

Returns current authorization handler.

Details

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

No description

Parameters

IUserStorage $storage
IAuthenticator $authenticator
IAuthorizator $authorizator

at line 69
IUserStorage getStorage()

No description

Return Value

IUserStorage

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

Conducts the authentication process. Parameters are optional.

Parameters

$user
$password

Return Value

void

Exceptions

AuthenticationException

at line 102
void logout($clearIdentity = false)

Logs out the user from the current session.

Parameters

$clearIdentity

Return Value

void

at line 118
bool isLoggedIn()

Is this user authenticated?

Return Value

bool

at line 128
IIdentity|null getIdentity()

Returns current user identity, if any.

Return Value

IIdentity|null

at line 138
mixed getId()

Returns current user ID, if any.

Return Value

mixed

at line 149
User setAuthenticator(IAuthenticator $handler)

Sets authentication handler.

Parameters

IAuthenticator $handler

Return Value

User

at line 160
IAuthenticator|null getAuthenticator($throw = true)

Returns authentication handler.

Parameters

$throw

Return Value

IAuthenticator|null

at line 176
User setExpiration($time, $flags = null, $clearIdentity = false)

Enables log out after inactivity.

Parameters

$time
$flags
$clearIdentity

Return Value

User

at line 188
int|null getLogoutReason()

Why was user logged out?

Return Value

int|null

at line 201
array getRoles()

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

Return Value

array

at line 217
bool isInRole($role)

Is a user in the specified effective role?

Parameters

$role

Return Value

bool

at line 230
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 246
User setAuthorizator(IAuthorizator $handler)

Sets authorization handler.

Parameters

IAuthorizator $handler

Return Value

User

at line 257
IAuthorizator|null getAuthorizator($throw = true)

Returns current authorization handler.

Parameters

$throw

Return Value

IAuthorizator|null

Traits

SmartObject