Class TUser
Direct Known Sub-classes:
TUser class
TUser implements basic user functionality for a Prado application. To get the name of the user, use Name property. The property IsGuest tells if the user a guest/anonymous user. To obtain or test the roles that the user is in, use property Roles and call isInRole(), respectively. TUser is meant to be used together with IUserManager.
Constructor Summary |
public |
Constructor.
|
Method Summary |
boolean
|
|
IUserManager
|
|
string
|
|
array
|
|
protected
mixed
|
getState
( string $key, mixed $defaultValue)
Returns the value of a variable that is stored in user session.
|
boolean
|
|
boolean
|
|
IUser
|
|
string
|
|
void
|
|
void
|
|
array|string
|
|
protected
void
|
setState
( string $key, mixed $value, mixed $defaultValue)
Stores a variable in user session.
|
void
|
|
Methods Inherited From TComponent |
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
Constructor Details |
__construct
Constructor.
|
Method Details |
getIsGuest
public boolean getIsGuest |
() |
Output |
boolean
| if the user is a guest, defaults to true. |
Exception |
|
getManager
|
getName
Output |
string
| username, defaults to empty string. |
Exception |
|
getRoles
Output |
array
| list of roles that the user is of |
Exception |
|
getState
protected mixed getState |
(string $key , mixed $defaultValue ) |
Returns the value of a variable that is stored in user session.
This function is designed to be used by TUser descendant classes who want to store additional user information in user session. A variable, if stored in user session using setState can be retrieved back using this function.
Input |
string | $key | variable name |
mixed | $defaultValue | default value |
Output |
mixed
| the value of the variable. If it doesn't exist, the provided default value will be returned |
Exception |
|
getStateChanged
public boolean getStateChanged |
() |
Output |
boolean
| whether user session state is changed (i.e., setState() is called) |
Exception |
|
isInRole
public boolean isInRole |
(string $role ) |
Input |
string | $role | role to be tested. Note, role is case-insensitive. |
Output |
boolean
| whether the user is of this role |
Exception |
|
loadFromString
public IUser loadFromString |
(string $data ) |
Input |
string | $data | user data that is serialized and restored from session |
Output |
IUser
| the user object |
Exception |
|
saveToString
public string saveToString |
() |
Output |
string
| user data that is serialized and will be stored in session |
Exception |
|
setIsGuest
public void setIsGuest |
(boolean $value ) |
Input |
boolean | $value | if the user is a guest |
Output |
Exception |
|
setName
public void setName |
(string $value ) |
Input |
string | $value | username |
Output |
Exception |
|
setRoles
public array|string setRoles |
(mixed $value ) |
Input |
mixed | $value | |
Output |
array|string
| list of roles that the user is of. If it is a string, roles are assumed by separated by comma |
Exception |
|
setState
protected void setState |
(string $key , mixed $value , mixed $defaultValue ) |
Stores a variable in user session.
This function is designed to be used by TUser descendant classes who want to store additional user information in user session. By storing a variable using this function, the variable may be retrieved back later using getState. The variable will be persistent across page requests during a user session.
Input |
string | $key | variable name |
mixed | $value | variable value |
mixed | $defaultValue | default value. If $value===$defaultValue, the variable will be removed from persistent storage. |
Output |
Exception |
|
setStateChanged
public void setStateChanged |
(boolean $value ) |
Input |
boolean | $value | whether user session state is changed |
Output |
Exception |
|
|