CRM_Core_Session
class CRM_Core_Session
Class CRM_Core_Session.
Constants
USER_CONTEXT |
|
Properties
static array | $_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 82
CRM_Core_Session
__construct()
Constructor.
The CMS takes care of initiating the php session handler session_start().
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 91
static CRM_Core_Session
singleton()
Singleton function used to manage this object.
at line 106
initialize(bool $isRead = FALSE)
Creates an array in the session.
All variables now will be stored under this array.
at line 146
reset(int $all = 1)
Resets the session store.
at line 168
createScope(string $prefix, bool $isRead = FALSE)
Creates a session local scope.
at line 186
resetScope(string $prefix)
Resets the session local scope.
at line 214
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 249
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 278
getVars(array $vars, string $prefix = '')
Gets all the variables in the current session scope and stuffs them in an associate array.
at line 313
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 330
pushUserContext(string $userContext, bool $check = TRUE)
Adds a userContext to the stack.
at line 365
replaceUserContext(string $userContext)
Replace the userContext of the stack with the passed one.
at line 382
string
popUserContext()
Pops the top userContext stack.
at line 394
string
readUserContext()
Reads the top userContext stack.
at line 407
debug(int $all = 1)
Dumps the session to the log.
at line 426
string
getStatus(bool $reset = FALSE)
Fetches status messages.
at line 466
static
setStatus(string $text, string $title = '', string $type = 'alert', array $options = [])
Stores an alert to be displayed to the user via crm-messages.
at line 504
static
registerAndRetrieveSessionObjects(string|array $names)
Register and retrieve session objects.
at line 524
static
storeSessionObjects(bool $reset = TRUE)
Store session objects.
at line 542
static int|null
getLoggedInContactID()
Retrieve contact id of the logged in user.
at line 557
string
getLoggedInContactDisplayName()
Get display name of the logged in user.
at line 572
bool
isEmpty()
Check if session is empty.
if so we don't cache stuff that we can get away with, helps proxies like varnish.