PHP Class Gdn_Session, vanilla

Mostrar archivo Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$User A User object containing properties relevant to session
$UserID Unique user identifier.

Protected Properties

Property Type Description
$_Attributes Attributes of the current user.
$_Preferences Preferences of the current user.
$_TransientKey The current user's transient key.

Public Methods

Method Description
__construct ( ) Private constructor prevents direct instantiation of object
addPermissions ( array $perms ) Add the permissions from a permissions array to this session's permissions.
checkPermission ( string | array $permission, boolean $fullMatch = true, string $junctionTable = '', integer | string $junctionID = '' ) : boolean Checks the currently authenticated user's permissions for the specified permission.
checkRankedPermission ( boolean | string $permission ) : boolean Check the given permission, but also return true if the user has a higher permission.
end ( Gdn_Authenticator $Authenticator = null ) End a session
ensureTransientKey ( ) : boolean | object | string
getAttribute ( unknown_type $AttributeName, string $DefaultValue = false ) : mixed Gets the currently authenticated user's attribute for the specified $AttributeName.
getAttributes ( ) : array
getCookie ( $Suffix, null $Default = null ) : mixed
getInstance ( ) : Session This is the singleton method that return the static Configuration::Instance.
getPermissions ( ) : array Returns all "allowed" permissions for the authenticated user in a one-dimensional array of permission names.
getPermissionsArray ( ) : array Returns all "allowed" permissions for the authenticated user in a one-dimensional array of permission names.
getPreference ( string $PreferenceName, mixed $DefaultValue = false ) : mixed Gets the currently authenticated user's preference for the specified $PreferenceName.
getPublicStash ( string $name, boolean $unset = false ) : mixed Get a public stash value.
getTimeZone ( ) : DateTimeZone Return the time zone for the current user.
hourOffset ( ) : integer Return the timezone hour difference between the user and utc.
isValid ( ) : boolean Ensure that there is an active session.
newVisit ( ) : boolean
setAttribute ( string | array $Name, mixed $Value = '' ) Sets a value in the $this->_Attributes array. This setting will persist only to the end of the page load. It is not intended for making permanent changes to user attributes.
setCookie ( $Suffix, $Value, $Expires )
setPermission ( string | array $PermissionName, null | boolean $Value = null ) : null Set a permission for the current runtime.
setPreference ( string | array $Name, mixed $Value = '', $SaveToDatabase = true ) Sets a value in the $this->_Preferences array. This setting will persist changes to user prefs.
setPublicStash ( string $name, mixed $value ) : Gdn_Session Sets a public stash value.
start ( integer $UserID = false, boolean $SetIdentity = true, boolean $Persist = false ) Authenticates the user with the provided Authenticator class.
stash ( string $name = '', mixed $value = '', boolean $unsetOnRetrieve = true ) : mixed Place a name/value pair into the user's session stash.
transientKey ( $NewKey = null ) : string Returns the transient key for the authenticated user.
validateTransientKey ( string $ForeignKey, $ValidateUser = true ) : boolean Validates that $ForeignKey was generated by the current user.

Private Methods

Method Description
getStashSession ( Gdn_SQLDriver $sql, string $valueToStash ) : boolean | Gdn_DataSet Used by $this->stash() to create & manage sessions for users & guests.

Method Details

__construct() public method

Private constructor prevents direct instantiation of object
public __construct ( )

addPermissions() public method

Add the permissions from a permissions array to this session's permissions.
public addPermissions ( array $perms )
$perms array The permissions to add.

checkPermission() public method

Returns a boolean value indicating if the action is permitted.
public checkPermission ( string | array $permission, boolean $fullMatch = true, string $junctionTable = '', integer | string $junctionID = '' ) : boolean
$permission string | array The permission (or array of permissions) to check.
$fullMatch boolean If $Permission is an array, $FullMatch indicates if all permissions specified are required. If false, the user only needs one of the specified permissions.
$junctionTable string The name of the junction table for a junction permission.
$junctionID integer | string The JunctionID associated with $Permission (ie. A discussion category identifier).
return boolean Returns **true** if the user has permission or **false** otherwise.

checkRankedPermission() public method

Check the given permission, but also return true if the user has a higher permission.
public checkRankedPermission ( boolean | string $permission ) : boolean
$permission boolean | string The permission to check. Bool to force true/false.
return boolean True on valid authorization, false on failure to authorize

end() public method

End a session
public end ( Gdn_Authenticator $Authenticator = null )
$Authenticator Gdn_Authenticator

ensureTransientKey() public method

getAttribute() public method

Gets the currently authenticated user's attribute for the specified $AttributeName.
public getAttribute ( unknown_type $AttributeName, string $DefaultValue = false ) : mixed
$AttributeName unknown_type The name of the attribute to get.
$DefaultValue string The default value to return if the attribute does not exist.
return mixed

getAttributes() public method

public getAttributes ( ) : array
return array

getCookie() public method

public getCookie ( $Suffix, null $Default = null ) : mixed
$Suffix
$Default null
return mixed

getInstance() public static method

This is the singleton method that return the static Configuration::Instance.
public static getInstance ( ) : Session
return Session

getPermissions() public method

Returns all "allowed" permissions for the authenticated user in a one-dimensional array of permission names.
Deprecation: We want to make this an accessor for the permissions property.
public getPermissions ( ) : array
return array

getPermissionsArray() public method

Returns all "allowed" permissions for the authenticated user in a one-dimensional array of permission names.
public getPermissionsArray ( ) : array
return array

getPreference() public method

Gets the currently authenticated user's preference for the specified $PreferenceName.
public getPreference ( string $PreferenceName, mixed $DefaultValue = false ) : mixed
$PreferenceName string The name of the preference to get.
$DefaultValue mixed The default value to return if the preference does not exist.
return mixed

getPublicStash() public method

Get a public stash value.
public getPublicStash ( string $name, boolean $unset = false ) : mixed
$name string The key of the stash.
$unset boolean Whether or not to unset the stash.
return mixed Returns the value of the stash.

getTimeZone() public method

Return the time zone for the current user.
public getTimeZone ( ) : DateTimeZone
return DateTimeZone Returns the current timezone.

hourOffset() public method

Return the timezone hour difference between the user and utc.
public hourOffset ( ) : integer
return integer The hour offset.

isValid() public method

If there isn't an active session, send the user to the SignIn Url
public isValid ( ) : boolean
return boolean

newVisit() public method

public newVisit ( ) : boolean
return boolean

setAttribute() public method

Sets a value in the $this->_Attributes array. This setting will persist only to the end of the page load. It is not intended for making permanent changes to user attributes.
public setAttribute ( string | array $Name, mixed $Value = '' )
$Name string | array
$Value mixed

setCookie() public method

public setCookie ( $Suffix, $Value, $Expires )
$Suffix
$Value
$Expires

setPermission() public method

Set a permission for the current runtime.
public setPermission ( string | array $PermissionName, null | boolean $Value = null ) : null
$PermissionName string | array
$Value null | boolean
return null

setPreference() public method

Sets a value in the $this->_Preferences array. This setting will persist changes to user prefs.
public setPreference ( string | array $Name, mixed $Value = '', $SaveToDatabase = true )
$Name string | array
$Value mixed

setPublicStash() public method

Sets a public stash value.
public setPublicStash ( string $name, mixed $value ) : Gdn_Session
$name string The key of the stash value.
$value mixed The value of the stash to set. Pass null to clear the key.
return Gdn_Session $this Returns $this for chaining.

start() public method

Authenticates the user with the provided Authenticator class.
public start ( integer $UserID = false, boolean $SetIdentity = true, boolean $Persist = false )
$UserID integer The UserID to start the session with.
$SetIdentity boolean Whether or not to set the identity (cookie) or make this a one request session.
$Persist boolean If setting an identity, should we persist it beyond browser restart?

stash() public method

Place a name/value pair into the user's session stash.
public stash ( string $name = '', mixed $value = '', boolean $unsetOnRetrieve = true ) : mixed
$name string The key of the stash value.
$value mixed The value of the stash to set. Pass null to retrieve the key.
$unsetOnRetrieve boolean Whether or not to unset the key from stash.
return mixed Returns the value of the stash or null on failure.

transientKey() public method

Returns the transient key for the authenticated user.
public transientKey ( $NewKey = null ) : string
return string

validateTransientKey() public method

Validates that $ForeignKey was generated by the current user.
public validateTransientKey ( string $ForeignKey, $ValidateUser = true ) : boolean
$ForeignKey string The key to validate.
return boolean

Property Details

$User public_oe property

A User object containing properties relevant to session
public $User

$UserID public_oe property

Unique user identifier.
public $UserID

$_Attributes protected_oe property

Attributes of the current user.
protected $_Attributes

$_Preferences protected_oe property

Preferences of the current user.
protected $_Preferences

$_TransientKey protected_oe property

The current user's transient key.
protected $_TransientKey