PHP Class ElggSession, Elgg

This class is intended to extend the $_SESSION magic variable by providing an API hook to plug in other values. Primarily this is intended to provide a way of supplying "logged in user" details without touching the session (which can cause problems when accessed server side). If a value is present in the session then that value is returned, otherwise a plugin hook 'session:get', '$var' is called, where $var is the variable being requested. Setting values will store variables in the session in the normal way. LIMITATIONS: You can not access multidimensional arrays This is EXPERIMENTAL.
Inheritance: implements ArrayAccess
Exibir arquivo Open project: elgg/elgg Class Usage Examples

Protected Properties

Property Type Description
$ignore_access boolean
$logged_in_user ElggUser | null
$storage Symfony\Component\HttpFoundation\Session\SessionInterface

Public Methods

Method Description
__construct ( Symfony\Component\HttpFoundation\Session\SessionInterface $storage ) Constructor
get ( string $name, mixed $default = null ) : mixed Get an attribute of the session
getId ( ) : string Get the session ID
getIgnoreAccess ( ) : boolean Get current ignore access setting.
getLoggedInUser ( ) : ElggUser | null Gets the logged in user
getLoggedInUserGuid ( ) : integer Return the current logged in user by guid.
getMock ( ) : self Get an isolated ElggSession that does not persist between requests
getName ( ) : string Get the session name
has ( string $name ) : boolean Has the attribute been defined
invalidate ( ) : boolean Invalidates the session
isAdminLoggedIn ( ) : boolean Returns whether or not the viewer is currently logged in and an admin user.
isLoggedIn ( ) : boolean Returns whether or not the user is currently logged in
isStarted ( ) : boolean Has the session been started
migrate ( boolean $destroy = false ) : boolean Migrates the session to a new session id while maintaining session attributes
remove ( string $name ) : mixed Remove an attribute
removeLoggedInUser ( ) : void Remove the logged in user
set ( string $name, mixed $value ) : void Set an attribute
setId ( string $id ) : void Set the session ID
setIgnoreAccess ( boolean $ignore = true ) : boolean Set ignore access.
setLoggedInUser ( ElggUser $user ) : void Sets the logged in user
setName ( string $name ) : void Set the session name
start ( ) : boolean Start the session

Protected Methods

Method Description
generateSessionToken ( ) : void Adds a token to the session

Method Details

__construct() public method

Constructor
public __construct ( Symfony\Component\HttpFoundation\Session\SessionInterface $storage )
$storage Symfony\Component\HttpFoundation\Session\SessionInterface The underlying Session implementation

generateSessionToken() protected method

This is used in creation of CSRF token, and is passed to the client to allow validating tokens later, even if the PHP session was destroyed.
protected generateSessionToken ( ) : void
return void

get() public method

Get an attribute of the session
public get ( string $name, mixed $default = null ) : mixed
$name string Name of the attribute to get
$default mixed Value to return if attribute is not set (default is null)
return mixed

getId() public method

Get the session ID
Since: 1.9
public getId ( ) : string
return string

getIgnoreAccess() public method

Get current ignore access setting.
public getIgnoreAccess ( ) : boolean
return boolean

getLoggedInUser() public method

Gets the logged in user
Since: 1.9
public getLoggedInUser ( ) : ElggUser | null
return ElggUser | null

getLoggedInUserGuid() public method

Return the current logged in user by guid.
See also: elgg_get_logged_in_user_entity()
public getLoggedInUserGuid ( ) : integer
return integer

getMock() public static method

Get an isolated ElggSession that does not persist between requests
public static getMock ( ) : self
return self

getName() public method

Get the session name
Since: 1.9
public getName ( ) : string
return string

has() public method

Has the attribute been defined
Since: 1.9
public has ( string $name ) : boolean
$name string Name of the attribute
return boolean

invalidate() public method

Deletes session data and session persistence. Starts a new session.
Since: 1.9
public invalidate ( ) : boolean
return boolean

isAdminLoggedIn() public method

Returns whether or not the viewer is currently logged in and an admin user.
public isAdminLoggedIn ( ) : boolean
return boolean

isLoggedIn() public method

Returns whether or not the user is currently logged in
public isLoggedIn ( ) : boolean
return boolean

isStarted() public method

Has the session been started
Since: 1.9
public isStarted ( ) : boolean
return boolean

migrate() public method

Migrates the session to a new session id while maintaining session attributes
Since: 1.9
public migrate ( boolean $destroy = false ) : boolean
$destroy boolean Whether to delete the session or let gc handle clean up
return boolean

remove() public method

Remove an attribute
Since: 1.9
public remove ( string $name ) : mixed
$name string The name of the attribute to remove
return mixed The removed attribute

removeLoggedInUser() public method

Remove the logged in user
Since: 1.9
public removeLoggedInUser ( ) : void
return void

set() public method

Set an attribute
public set ( string $name, mixed $value ) : void
$name string Name of the attribute to set
$value mixed Value to be set
return void

setId() public method

Set the session ID
Since: 1.9
public setId ( string $id ) : void
$id string Session ID
return void

setIgnoreAccess() public method

Set ignore access.
public setIgnoreAccess ( boolean $ignore = true ) : boolean
$ignore boolean Ignore access
return boolean Previous setting

setLoggedInUser() public method

Sets the logged in user
Since: 1.9
public setLoggedInUser ( ElggUser $user ) : void
$user ElggUser The user who is logged in
return void

setName() public method

Set the session name
Since: 1.9
public setName ( string $name ) : void
$name string Session name
return void

start() public method

Start the session
Since: 1.9
public start ( ) : boolean
return boolean

Property Details

$ignore_access protected_oe property

protected bool $ignore_access
return boolean

$logged_in_user protected_oe property

protected ElggUser|null $logged_in_user
return ElggUser | null

$storage protected_oe property

protected SessionInterface,Symfony\Component\HttpFoundation\Session $storage
return Symfony\Component\HttpFoundation\Session\SessionInterface