PHP Class Prado\Security\TUser

TUser implements basic user functionality for a Prado application. To get the name of the user, use {@link getName Name} property. The property {@link getIsGuest IsGuest} tells if the user a guest/anonymous user. To obtain or test the roles that the user is in, use property {@link getRoles Roles} and call {@link isInRole()}, respectively. TUser is meant to be used together with {@link IUserManager}.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends Prado\TComponent, implements Prado\Security\IUser
Show file Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__construct ( IUserManager $manager ) Constructor.
getIsGuest ( ) : boolean
getManager ( ) : IUserManager
getName ( ) : string
getRoles ( ) : array
getStateChanged ( ) : boolean
isInRole ( $role ) : boolean
loadFromString ( $data ) : Prado\Security\IUser
saveToString ( ) : string
setIsGuest ( $value )
setName ( $value )
setRoles ( $value ) : array | string
setStateChanged ( $value )

Protected Methods

Method Description
getState ( $key, $defaultValue = null ) : mixed Returns the value of a variable that is stored in user session.
setState ( $key, $value, $defaultValue = null ) Stores a variable in user session.

Method Details

__construct() public method

Constructor.
public __construct ( IUserManager $manager )
$manager IUserManager

getIsGuest() public method

public getIsGuest ( ) : boolean
return boolean if the user is a guest, defaults to true.

getManager() public method

public getManager ( ) : IUserManager
return IUserManager user manager

getName() public method

public getName ( ) : string
return string username, defaults to empty string.

getRoles() public method

public getRoles ( ) : array
return array list of roles that the user is of

getState() protected method

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 {@link setState} can be retrieved back using this function.
See also: setState
protected getState ( $key, $defaultValue = null ) : mixed
return mixed the value of the variable. If it doesn't exist, the provided default value will be returned

getStateChanged() public method

public getStateChanged ( ) : boolean
return boolean whether user session state is changed (i.e., setState() is called)

isInRole() public method

public isInRole ( $role ) : boolean
return boolean whether the user is of this role

loadFromString() public method

public loadFromString ( $data ) : Prado\Security\IUser
return Prado\Security\IUser the user object

saveToString() public method

public saveToString ( ) : string
return string user data that is serialized and will be stored in session

setIsGuest() public method

public setIsGuest ( $value )

setName() public method

public setName ( $value )

setRoles() public method

public setRoles ( $value ) : array | string
return array | string list of roles that the user is of. If it is a string, roles are assumed by separated by comma

setState() protected method

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 {@link getState}. The variable will be persistent across page requests during a user session.
See also: getState
protected setState ( $key, $value, $defaultValue = null )

setStateChanged() public method

public setStateChanged ( $value )