class User

User authentication and authorization.

Constants

deprecated MANUAL

deprecated INACTIVITY

LogoutManual

Log-out reason

LogoutInactivity

Log-out reason

LOGOUT_MANUAL

LOGOUT_INACTIVITY

Properties

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

Methods

__construct(IUserStorage|null $legacyStorage = null, IAuthenticator|null $authenticator = null, Authorizator|null $authorizator = null, UserStorage|null $storage = null)

No description

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

mixed
getId()

Returns current user ID, if any.

void
refreshStorage()

No description

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|bool $clearIdentity = null)

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.

Authorizator|null
getAuthorizator()

Returns current authorization handler.

Authorizator|null
getAuthorizatorIfExists()

Returns current authorization handler.

bool
hasAuthorizator() deprecated

No description

Details

at line 75
__construct(IUserStorage|null $legacyStorage = null, IAuthenticator|null $authenticator = null, Authorizator|null $authorizator = null, UserStorage|null $storage = null)

No description

Parameters

IUserStorage|null $legacyStorage
IAuthenticator|null $authenticator
Authorizator|null $authorizator
UserStorage|null $storage

at line 94
final UserStorage|IUserStorage getStorage()

No description

Return Value

UserStorage|IUserStorage

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

Conducts the authentication process. Parameters are optional.

Parameters

string|IIdentity $user

name or Identity

string|null $password

Return Value

void

Exceptions

AuthenticationException

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

Logs out the user from the current session.

Parameters

bool $clearIdentity

Return Value

void

at line 169
final bool isLoggedIn()

Is this user authenticated?

Return Value

bool

at line 182
final IIdentity|null getIdentity()

Returns current user identity, if any.

Return Value

IIdentity|null

at line 217
mixed getId()

Returns current user ID, if any.

Return Value

mixed

at line 224
final void refreshStorage()

No description

Return Value

void

at line 234
User setAuthenticator(IAuthenticator $handler)

Sets authentication handler.

Parameters

IAuthenticator $handler

Return Value

User

at line 244
final IAuthenticator|null getAuthenticator()

Returns authentication handler.

Return Value

IAuthenticator|null

at line 262
final IAuthenticator|null getAuthenticatorIfExists()

Returns authentication handler.

Return Value

IAuthenticator|null

at line 269
final bool hasAuthenticator() deprecated

deprecated

No description

Return Value

bool

at line 281
User setExpiration(string|null $expire, int|bool $clearIdentity = null)

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

Parameters

string|null $expire
int|bool $clearIdentity

Return Value

User

at line 303
final int|null getLogoutReason()

Why was user logged out? Returns LOGOUT_MANUAL or LOGOUT_INACTIVITY.

Return Value

int|null

at line 315
array getRoles()

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

Return Value

array

at line 329
final bool isInRole(string $role)

Is a user in the specified effective role?

Parameters

string $role

Return Value

bool

at line 345
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 361
User setAuthorizator(Authorizator $handler)

Sets authorization handler.

Parameters

Authorizator $handler

Return Value

User

at line 371
final Authorizator|null getAuthorizator()

Returns current authorization handler.

Return Value

Authorizator|null

at line 389
final Authorizator|null getAuthorizatorIfExists()

Returns current authorization handler.

Return Value

Authorizator|null

at line 396
final bool hasAuthorizator() deprecated

deprecated

No description

Return Value

bool

Traits

SmartObject