<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
* @var string
*/
protected $_key = 'CiviCRM';
- CONST USER_CONTEXT = 'userContext';
+ const USER_CONTEXT = 'userContext';
/**
* This is just a reference to the real session. Allows us to
/**
* Constructor
*
- * Since we are now a client / module of drupal, drupal takes care
- * of initiating the php session handler session_start ().
+ * The CMS takes care of initiating the php session handler session_start().
*
- * When using CiviCRM standalone (i.e. w/o Drupal), we start the session
+ * 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 drupal and also
- * collisions with other crm modules!!
+ * 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.
*
- * @return \CRM_Core_Session
+ * @return CRM_Core_Session
*/
- function __construct() {
- $this->_session = null;
+ public function __construct() {
+ $this->_session = NULL;
}
/**
* @return CRM_Core_Session
* @static
*/
- static function &singleton() {
+ public static function &singleton() {
if (self::$_singleton === NULL) {
self::$_singleton = new CRM_Core_Session;
}
* Creates an array in the session. All variables now will be stored
* under this array
*
- * @param boolean isRead is this a read operation, in this case, the session will not be touched
+ * @param bool $isRead
+ * Is this a read operation, in this case, the session will not be touched.
*
- * @access private
*
* @return void
*/
- function initialize($isRead = FALSE) {
+ public function initialize($isRead = FALSE) {
// lets initialize the _session variable just before we need it
// hopefully any bootstrapping code will actually load the session from the CMS
if (!isset($this->_session)) {
return;
}
$config =& CRM_Core_Config::singleton();
+ // FIXME: This belongs in CRM_Utils_System_*
if ($config->userSystem->is_drupal && function_exists('drupal_session_start')) {
// https://issues.civicrm.org/jira/browse/CRM-14356
- if (! (isset($GLOBALS['lazy_session']) && $GLOBALS['lazy_session'] == true)) {
+ if (! (isset($GLOBALS['lazy_session']) && $GLOBALS['lazy_session'] == TRUE)) {
drupal_session_start();
}
$_SESSION = array();
/**
* Resets the session store
*
- * @access public
*
* @param int $all
*
* @return void
*/
- function reset($all = 1) {
+ public function reset($all = 1) {
if ($all != 1) {
$this->initialize();
/**
* Creates a session local scope
*
- * @param string prefix local scope name
- * @param boolean isRead is this a read operation, in this case, the session will not be touched
+ * @param string $prefix
+ * Local scope name.
+ * @param bool $isRead
+ * Is this a read operation, in this case, the session will not be touched.
*
- * @access public
*
* @return void
*/
- function createScope($prefix, $isRead = FALSE) {
+ public function createScope($prefix, $isRead = FALSE) {
$this->initialize($isRead);
if ($isRead || empty($prefix)) {
/**
* Resets the session local scope
*
- * @param string local scope name
- * @access public
+ * @param string $prefix
+ * Local scope name.
*
* @return void
*/
- function resetScope($prefix) {
+ public function resetScope($prefix) {
$this->initialize();
if (empty($prefix)) {
* to store complex objects in the session. I suspect it
* is supported but we need to verify this
*
- * @access public
*
- * @param string $name name of the variable
- * @param mixed $value value of the variable
- * @param string $prefix a string to prefix the keys in the session with
+ * @param string $name
+ * Name of the variable.
+ * @param mixed $value
+ * Value of the variable.
+ * @param string $prefix
+ * A string to prefix the keys in the session with.
*
* @return void
*
*/
- function set($name, $value = NULL, $prefix = NULL) {
+ public function set($name, $value = NULL, $prefix = NULL) {
// create session scope
$this->createScope($prefix);
* This function takes a name and retrieves the value of this
* variable from the session scope.
*
- * @access public
*
- * @param string name : name of the variable
- * @param string prefix : adds another level of scope to the session
+ * @param string $name
+ * : name of the variable.
+ * @param string $prefix
+ * : adds another level of scope to the session.
*
* @return mixed
*
*/
- function get($name, $prefix = NULL) {
+ public function get($name, $prefix = NULL) {
// create session scope
$this->createScope($prefix, TRUE);
if (empty($this->_session) || empty($this->_session[$this->_key])) {
- return null;
+ return NULL;
}
if (empty($prefix)) {
}
else {
if (empty($this->_session[$this->_key][$prefix])) {
- return null;
+ return NULL;
}
$session =& $this->_session[$this->_key][$prefix];
}
* Gets all the variables in the current session scope
* and stuffs them in an associate array
*
- * @access public
*
- * @param array vars : associative array to store name/value pairs
- * @param string Strip prefix from the key before putting it in the return
+ * @param array $vars
+ * Associative array to store name/value pairs.
+ * @param string $prefix
+ * Will be stripped from the key before putting it in the return.
*
* @return void
*
*/
- function getVars(&$vars, $prefix = '') {
+ public function getVars(&$vars, $prefix = '') {
// create session scope
$this->createScope($prefix, TRUE);
* 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
*
- * @access public
*
- * @param string name : name of the timer
- * @param int expire : expiry time (in seconds)
+ * @param string $name
+ * : name of the timer.
+ * @param int $expire
+ * : expiry time (in seconds).
*
* @return mixed
*
*/
- function timer($name, $expire) {
+ public function timer($name, $expire) {
$ts = $this->get($name, 'timer');
if (!$ts || $ts < time() - $expire) {
$this->set($name, time(), 'timer');
return $ts ? $ts : 'not set';
}
- return false;
+ return FALSE;
}
/**
* Adds a userContext to the stack
*
- * @param string $userContext the url to return to when done
- * @param boolean $check should we do a dupe checking with the top element
+ * @param string $userContext
+ * The url to return to when done.
+ * @param bool $check
+ * Should we do a dupe checking with the top element.
*
* @return void
*
- * @access public
*
*/
- function pushUserContext($userContext, $check = TRUE) {
+ public function pushUserContext($userContext, $check = TRUE) {
if (empty($userContext)) {
return;
}
/**
* Replace the userContext of the stack with the passed one
*
- * @param string the url to return to when done
+ * @param string $userContext
+ * The url to return to when done.
*
* @return void
*
- * @access public
*
*/
- function replaceUserContext($userContext) {
+ public function replaceUserContext($userContext) {
if (empty($userContext)) {
return;
}
/**
* Pops the top userContext stack
*
- * @param void
- *
- * @return the top of the userContext stack (also pops the top element)
+ * @return string the top of the userContext stack (also pops the top element)
*
*/
- function popUserContext() {
+ public function popUserContext() {
$this->createScope(self::USER_CONTEXT);
return array_pop($this->_session[$this->_key][self::USER_CONTEXT]);
/**
* Reads the top userContext stack
*
- * @param void
- *
- * @return the top of the userContext stack
+ * @return string the top of the userContext stack
*
*/
- function readUserContext() {
+ public function readUserContext() {
$this->createScope(self::USER_CONTEXT);
$config = CRM_Core_Config::singleton();
/**
* Dumps the session to the log
+ * @param int $all
*/
- function debug($all = 1) {
+ public function debug($all = 1) {
$this->initialize();
if ($all != 1) {
CRM_Core_Error::debug('CRM Session', $this->_session);
/**
* Fetches status messages
*
- * @param $reset boolean should we reset the status variable?
+ * @param bool $reset
+ * Should we reset the status variable?.
*
* @return string the status message if any
*/
- function getStatus($reset = FALSE) {
+ public function getStatus($reset = FALSE) {
$this->initialize();
$status = NULL;
/**
* Stores an alert to be displayed to the user via crm-messages
*
- * @param $text string
+ * @param string $text
* The status message
*
- * @param $title string
+ * @param string $title
* The optional title of this message
*
- * @param $type string
+ * @param string $type
* The type of this message (printed as a css class). Possible options:
* - 'alert' (default)
* - 'info'
* until the user dismisses it)
* - 'no-popup' (will display in the document like old-school)
*
- * @param $options array
+ * @param array $options
* Additional options. Possible values:
* - 'unique' (default: true) Check if this message was already set before adding
* - 'expires' how long to display this message before fadeout (in ms)
*
* @return void
*/
- static function setStatus($text, $title = '', $type = 'alert', $options = array()) {
+ public static function setStatus($text, $title = '', $type = 'alert', $options = array()) {
// make sure session is initialized, CRM-8120
$session = self::singleton();
$session->initialize();
}
/**
- * @param string $names
+ * @param string|array $names
*/
- static function registerAndRetrieveSessionObjects($names) {
+ public static function registerAndRetrieveSessionObjects($names) {
if (!is_array($names)) {
$names = array($names);
}
/**
* @param bool $reset
*/
- static function storeSessionObjects($reset = TRUE) {
+ public static function storeSessionObjects($reset = TRUE) {
if (empty(self::$_managedNames)) {
return;
}
/**
* Retrieve contact id of the logged in user
- * @return integer | NULL contact ID of logged in user
+ * @return integer|NULL contact ID of logged in user
*/
- static function getLoggedInContactID() {
+ public static function getLoggedInContactID() {
$session = CRM_Core_Session::singleton();
if (!is_numeric($session->get('userID'))) {
return NULL;
/**
* @return bool
*/
- function isEmpty() {
- // check if session is empty, if so we dont cache
+ public function isEmpty() {
+ // check if session is empty, if so we don't cache
// stuff that we can get away with
// helps proxies like varnish
- return empty($_SESSION) ? TRUE : FALSE;
+ return empty($_SESSION);
}
}