CRM_Core_Session
class CRM_Core_Session
Class CRM_Core_Session.
Constants
USER_CONTEXT |
|
Properties
static | $_managedNames | Cache of all the session names that we manage. | |
protected string | $_key | Key is used to allow the application to have multiple top level scopes rather than a single scope. (avoids naming conflicts). We also extend this idea further and have local scopes within a global scope. Allows us to do cool things like resetting a specific area of the session code while keeping the rest intact | |
protected object | $_session | This is just a reference to the real session. Allows us to debug this class a wee bit easier |
Methods
Constructor.
Singleton function used to manage this object.
Creates an array in the session.
Resets the session store.
Creates a session local scope.
Resets the session local scope.
Store the variable with the value in the session scope.
Gets the value of the named variable in the session scope.
Gets all the variables in the current session scope and stuffs them in an associate array.
Set and check a timer.
Adds a userContext to the stack.
Replace the userContext of the stack with the passed one.
Pops the top userContext stack.
Reads the top userContext stack.
Dumps the session to the log.
Fetches status messages.
Stores an alert to be displayed to the user via crm-messages.
Register and retrieve session objects.
Store session objects.
Retrieve contact id of the logged in user.
Get display name of the logged in user.
Check if session is empty.
Details
at line 84
CRM_Core_Session
__construct()
Constructor.
The CMS takes care of initiating the php session handler session_start().
When using CiviCRM standalone (w/o a CMS), we start the session in index.php and then pass it off to here.
All crm code should always use the session using CRM_Core_Session. we prefix stuff to avoid collisions with the CMS and also collisions with other crm modules!
This constructor is invoked whenever any module requests an instance of the session and one is not available.
at line 93
static CRM_Core_Session
singleton()
Singleton function used to manage this object.
at line 108
initialize(bool $isRead = FALSE)
Creates an array in the session.
All variables now will be stored under this array.
at line 149
reset(int $all = 1)
Resets the session store.
at line 171
createScope(string $prefix, bool $isRead = FALSE)
Creates a session local scope.
at line 189
resetScope(string $prefix)
Resets the session local scope.
at line 217
set(string $name, mixed $value = NULL, string $prefix = NULL)
Store the variable with the value in the session scope.
This function takes a name, value pair and stores this in the session scope. Not sure what happens if we try to store complex objects in the session. I suspect it is supported but we need to verify this
at line 252
mixed
get(string $name, string $prefix = NULL)
Gets the value of the named variable in the session scope.
This function takes a name and retrieves the value of this variable from the session scope.
at line 281
getVars(array $vars, string $prefix = '')
Gets all the variables in the current session scope and stuffs them in an associate array.
at line 316
mixed
timer(string $name, int $expire)
Set and check a timer.
If it's expired, it will be set again.
Good for showing a message to the user every hour or day (so not bugging them on every page) Returns true-ish values if the timer is not set or expired, and false if the timer is still running If you want to get more nuanced, you can check the type of the return to see if it's 'not set' or actually expired at a certain time
at line 333
pushUserContext(string $userContext, bool $check = TRUE)
Adds a userContext to the stack.
at line 368
replaceUserContext(string $userContext)
Replace the userContext of the stack with the passed one.
at line 385
string
popUserContext()
Pops the top userContext stack.
at line 397
string
readUserContext()
Reads the top userContext stack.
at line 410
debug(int $all = 1)
Dumps the session to the log.
at line 429
string
getStatus(bool $reset = FALSE)
Fetches status messages.
at line 469
static
setStatus(string $text, string $title = '', string $type = 'alert', array $options = array())
Stores an alert to be displayed to the user via crm-messages.
at line 503
static
registerAndRetrieveSessionObjects(string|array $names)
Register and retrieve session objects.
at line 523
static
storeSessionObjects(bool $reset = TRUE)
Store session objects.
at line 541
static int|NULL
getLoggedInContactID()
Retrieve contact id of the logged in user.
at line 556
string
getLoggedInContactDisplayName()
Get display name of the logged in user.
at line 571
bool
isEmpty()
Check if session is empty.
if so we don't cache stuff that we can get away with, helps proxies like varnish.