Elgg  Version 4.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ElggSession Class Reference

Elgg Session Management. More...

Public Member Functions

 __construct (SessionInterface $storage)
 Constructor. More...
 
 boot ()
 Initializes the session and checks for the remember me cookie. More...
 
 start ()
 Start the session. More...
 
 migrate ($destroy=false)
 Migrates the session to a new session id while maintaining session attributes. More...
 
 invalidate ()
 Invalidates the session. More...
 
 save ()
 Save the session data and closes the session. More...
 
 isStarted ()
 Has the session been started. More...
 
 getID ()
 Get the session ID. More...
 
 setId ($id)
 Set the session ID. More...
 
 getName ()
 Get the session name. More...
 
 setName ($name)
 Set the session name. More...
 
 get ($name, $default=null)
 Get an attribute of the session. More...
 
 set ($name, $value)
 Set an attribute. More...
 
 remove ($name)
 Remove an attribute. More...
 
 has ($name)
 Has the attribute been defined. More...
 
 login (\ElggUser $user, bool $persistent=false)
 Log in a user. More...
 
 logout ()
 Log the current user out. More...
 
 setLoggedInUser (\ElggUser $user)
 Sets the logged in user. More...
 
 getLoggedInUser ()
 Gets the logged in user. More...
 
 getLoggedInUserGuid ()
 Return the current logged in user by guid. More...
 
 isAdminLoggedIn ()
 Returns whether or not the viewer is currently logged in and an admin user. More...
 
 isLoggedIn ()
 Returns whether or not the user is currently logged in. More...
 
 removeLoggedInUser ()
 Remove the logged in user. More...
 
 setUserToken (\ElggUser $user=null)
 Set a user specific token in the session for the currently logged in user. More...
 
 validateUserToken (\ElggUser $user)
 Validate the user token stored in the session. More...
 
 getIgnoreAccess ()
 Get current ignore access setting. More...
 
 setIgnoreAccess ($ignore=true)
 Set ignore access. More...
 
 getDisabledEntityVisibility ()
 Are disabled entities shown? More...
 
 setDisabledEntityVisibility ($show=true)
 Include disabled entities in queries. More...
 

Static Public Member Functions

static getMock ()
 Get an isolated ElggSession that does not persist between requests. More...
 
static fromDatabase (Config $config, Database $db)
 Create a session stored in the DB. More...
 
static fromFiles (Config $config)
 Create a session stored in files. More...
 

Protected Member Functions

 generateUserToken (\ElggUser $user)
 Generate a token for a specific user. More...
 
 generateSessionToken ()
 Adds a token to the session. More...
 

Protected Attributes

 $storage
 
 $logged_in_user
 
 $ignore_access = false
 
 $show_disabled_entities = false
 

Detailed Description

Elgg Session Management.

Reserved keys: last_forward_from, msg, sticky_forms, user, guid, id, code, name, username

See also
elgg_get_session()

Definition at line 22 of file ElggSession.php.

Constructor & Destructor Documentation

ElggSession::__construct ( SessionInterface  $storage)

Constructor.

Parameters
SessionInterface$storageThe underlying Session implementation

Definition at line 51 of file ElggSession.php.

Member Function Documentation

ElggSession::boot ( )

Initializes the session and checks for the remember me cookie.

Returns
void

Definition at line 62 of file ElggSession.php.

static ElggSession::fromDatabase ( Config  $config,
Database  $db 
)
static

Create a session stored in the DB.

Parameters
Config$configConfig
Database$dbDatabase
Returns
ElggSession

Definition at line 545 of file ElggSession.php.

static ElggSession::fromFiles ( Config  $config)
static

Create a session stored in files.

Parameters
Config$configConfig
Returns
ElggSession

Definition at line 575 of file ElggSession.php.

ElggSession::generateSessionToken ( )
protected

Adds a token to the session.

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.

Returns
void

Definition at line 515 of file ElggSession.php.

ElggSession::generateUserToken ( \ElggUser  $user)
protected

Generate a token for a specific user.

Parameters
\ElggUser$userthe user to generate the token for
Returns
string
Since
3.3.25

Definition at line 452 of file ElggSession.php.

ElggSession::get (   $name,
  $default = null 
)

Get an attribute of the session.

Parameters
string$nameName of the attribute to get
mixed$defaultValue to return if attribute is not set (default is null)
Returns
mixed

Definition at line 214 of file ElggSession.php.

ElggSession::getDisabledEntityVisibility ( )

Are disabled entities shown?

Returns
bool

Definition at line 489 of file ElggSession.php.

ElggSession::getID ( )

Get the session ID.

Returns
string
Since
1.9

Definition at line 171 of file ElggSession.php.

ElggSession::getIgnoreAccess ( )

Get current ignore access setting.

Returns
bool

Definition at line 466 of file ElggSession.php.

ElggSession::getLoggedInUser ( )

Gets the logged in user.

Returns
|null
Since
1.9

Definition at line 358 of file ElggSession.php.

ElggSession::getLoggedInUserGuid ( )

Return the current logged in user by guid.

See also
elgg_get_logged_in_user_entity()
Returns
int

Definition at line 368 of file ElggSession.php.

static ElggSession::getMock ( )
static

Get an isolated ElggSession that does not persist between requests.

Returns
self

Definition at line 529 of file ElggSession.php.

ElggSession::getName ( )

Get the session name.

Returns
string
Since
1.9

Definition at line 192 of file ElggSession.php.

ElggSession::has (   $name)

Has the attribute been defined.

Parameters
string$nameName of the attribute
Returns
bool
Since
1.9

Definition at line 247 of file ElggSession.php.

ElggSession::invalidate ( )

Invalidates the session.

Deletes session data and session persistence. Starts a new session.

Returns
boolean
Since
1.9

Definition at line 136 of file ElggSession.php.

ElggSession::isAdminLoggedIn ( )

Returns whether or not the viewer is currently logged in and an admin user.

Returns
bool

Definition at line 378 of file ElggSession.php.

ElggSession::isLoggedIn ( )

Returns whether or not the user is currently logged in.

Returns
bool

Definition at line 389 of file ElggSession.php.

ElggSession::isStarted ( )

Has the session been started.

Returns
boolean
Since
1.9

Definition at line 161 of file ElggSession.php.

ElggSession::login ( \ElggUser  $user,
bool  $persistent = false 
)

Log in a user.

Parameters
\ElggUser$userA valid Elgg user object
boolean$persistentShould this be a persistent login?
Returns
void
Exceptions
LoginException
Since
4.3

Definition at line 261 of file ElggSession.php.

ElggSession::logout ( )

Log the current user out.

Returns
bool
Since
4.3

Definition at line 312 of file ElggSession.php.

ElggSession::migrate (   $destroy = false)

Migrates the session to a new session id while maintaining session attributes.

Parameters
boolean$destroyWhether to delete the session or let gc handle clean up
Returns
boolean
Since
1.9

Definition at line 124 of file ElggSession.php.

ElggSession::remove (   $name)

Remove an attribute.

Parameters
string$nameThe name of the attribute to remove
Returns
mixed The removed attribute
Since
1.9

Definition at line 236 of file ElggSession.php.

ElggSession::removeLoggedInUser ( )

Remove the logged in user.

Returns
void
Since
1.9

Definition at line 399 of file ElggSession.php.

ElggSession::save ( )

Save the session data and closes the session.

Returns
void
Since
3.0

Definition at line 151 of file ElggSession.php.

ElggSession::set (   $name,
  $value 
)

Set an attribute.

Parameters
string$nameName of the attribute to set
mixed$valueValue to be set
Returns
void

Definition at line 225 of file ElggSession.php.

ElggSession::setDisabledEntityVisibility (   $show = true)

Include disabled entities in queries.

Parameters
bool$showVisibility status
Returns
bool Previous setting

Definition at line 500 of file ElggSession.php.

ElggSession::setId (   $id)

Set the session ID.

Parameters
string$idSession ID
Returns
void
Since
1.9

Definition at line 182 of file ElggSession.php.

ElggSession::setIgnoreAccess (   $ignore = true)

Set ignore access.

Parameters
bool$ignoreIgnore access
Returns
bool Previous setting

Definition at line 477 of file ElggSession.php.

ElggSession::setLoggedInUser ( \ElggUser  $user)

Sets the logged in user.

Parameters
\ElggUser$userThe user who is logged in
Returns
void
Since
1.9

Definition at line 341 of file ElggSession.php.

ElggSession::setName (   $name)

Set the session name.

Parameters
string$nameSession name
Returns
void
Since
1.9

Definition at line 203 of file ElggSession.php.

ElggSession::setUserToken ( \ElggUser  $user = null)

Set a user specific token in the session for the currently logged in user.

This will invalidate the session on a password change of the logged in user

Parameters
\ElggUser$userthe user to set the token for (default: logged in user)
Returns
void
Since
3.3.25

Definition at line 415 of file ElggSession.php.

ElggSession::start ( )

Start the session.

Returns
boolean
Exceptions
RuntimeExceptionIf session fails to start.
Since
1.9

Definition at line 106 of file ElggSession.php.

ElggSession::validateUserToken ( \ElggUser  $user)

Validate the user token stored in the session.

Parameters
\ElggUser$userthe user to check for
Returns
void
Exceptions

Definition at line 435 of file ElggSession.php.

Member Data Documentation

ElggSession::$ignore_access = false
protected

Definition at line 39 of file ElggSession.php.

ElggSession::$logged_in_user
protected

Definition at line 34 of file ElggSession.php.

ElggSession::$show_disabled_entities = false
protected

Definition at line 44 of file ElggSession.php.

ElggSession::$storage
protected

Definition at line 29 of file ElggSession.php.


The documentation for this class was generated from the following file: