CRM-16478 Initial changes to remove custom error template path
[civicrm-core.git] / CRM / Core / Session.php
index 76335f97d0d6e4a313dabc66df414d7c72445f3b..002d10cf36330104a96977dab34b6222ba89e3b0 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 
 require_once "PEAR.php";
@@ -34,7 +34,7 @@ require_once "PEAR.php";
 class CRM_Core_Session {
 
   /**
-   * Cache of all the session names that we manage
+   * Cache of all the session names that we manage.
    */
   static $_managedNames = NULL;
 
@@ -64,12 +64,11 @@ class CRM_Core_Session {
    * pattern and cache the instance in this variable
    *
    * @var object
-   * @static
    */
   static private $_singleton = NULL;
 
   /**
-   * Constructor
+   * Constructor.
    *
    * The CMS takes care of initiating the php session handler session_start().
    *
@@ -86,18 +85,17 @@ class CRM_Core_Session {
    * @return CRM_Core_Session
    */
   public function __construct() {
-    $this->_session = null;
+    $this->_session = NULL;
   }
 
   /**
-   * Singleton function used to manage this object
+   * Singleton function used to manage this object.
    *
    * @return CRM_Core_Session
-   * @static
    */
   public static function &singleton() {
     if (self::$_singleton === NULL) {
-      self::$_singleton = new CRM_Core_Session;
+      self::$_singleton = new CRM_Core_Session();
     }
     return self::$_singleton;
   }
@@ -106,7 +104,8 @@ class 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.
    *
    *
    * @return void
@@ -124,7 +123,7 @@ class CRM_Core_Session {
         // 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();
@@ -145,11 +144,11 @@ class CRM_Core_Session {
     ) {
       $this->_session[$this->_key] = array();
     }
-    return;
+    return NULL;
   }
 
   /**
-   * Resets the session store
+   * Resets the session store.
    *
    *
    * @param int $all
@@ -168,14 +167,16 @@ class CRM_Core_Session {
       $this->_session = array();
     }
 
-    return;
+    return NULL;
   }
 
   /**
-   * Creates a session local scope
+   * 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.
    *
    *
    * @return void
@@ -193,9 +194,10 @@ class CRM_Core_Session {
   }
 
   /**
-   * Resets the session local scope
+   * Resets the session local scope.
    *
-   * @param string $prefix local scope name
+   * @param string $prefix
+   *   Local scope name.
    *
    * @return void
    */
@@ -212,7 +214,7 @@ class CRM_Core_Session {
   }
 
   /**
-   * Store the variable with the value in the session scope
+   * 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
@@ -220,12 +222,14 @@ class CRM_Core_Session {
    * is supported but we need to verify this
    *
    *
-   * @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
-   *
    */
   public function set($name, $value = NULL, $prefix = NULL) {
     // create session scope
@@ -249,24 +253,25 @@ class CRM_Core_Session {
   }
 
   /**
-   * Gets the value of the named variable in the session scope
+   * 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.
    *
    *
-   * @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
-   *
    */
   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)) {
@@ -274,7 +279,7 @@ class CRM_Core_Session {
     }
     else {
       if (empty($this->_session[$this->_key][$prefix])) {
-        return null;
+        return NULL;
       }
       $session =& $this->_session[$this->_key][$prefix];
     }
@@ -287,11 +292,12 @@ class CRM_Core_Session {
    * and stuffs them in an associate array
    *
    *
-   * @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
+   * @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
-   *
    */
   public function getVars(&$vars, $prefix = '') {
     // create session scope
@@ -318,11 +324,12 @@ class CRM_Core_Session {
    * 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
    *
    *
-   * @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
-   *
    */
   public function timer($name, $expire) {
     $ts = $this->get($name, 'timer');
@@ -330,18 +337,18 @@ class CRM_Core_Session {
       $this->set($name, time(), 'timer');
       return $ts ? $ts : 'not set';
     }
-    return false;
+    return FALSE;
   }
 
   /**
-   * Adds a userContext to the stack
+   * 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
-   *
-   *
    */
   public function pushUserContext($userContext, $check = TRUE) {
     if (empty($userContext)) {
@@ -373,13 +380,12 @@ class CRM_Core_Session {
   }
 
   /**
-   * Replace the userContext of the stack with the passed one
+   * Replace the userContext of the stack with the passed one.
    *
-   * @param string $userContext the url to return to when done
+   * @param string $userContext
+   *   The url to return to when done.
    *
    * @return void
-   *
-   *
    */
   public function replaceUserContext($userContext) {
     if (empty($userContext)) {
@@ -393,10 +399,10 @@ class CRM_Core_Session {
   }
 
   /**
-   * Pops the top userContext stack
-   *
-   * @return string the top of the userContext stack (also pops the top element)
+   * Pops the top userContext stack.
    *
+   * @return string
+   *   the top of the userContext stack (also pops the top element)
    */
   public function popUserContext() {
     $this->createScope(self::USER_CONTEXT);
@@ -405,10 +411,10 @@ class CRM_Core_Session {
   }
 
   /**
-   * Reads the top userContext stack
-   *
-   * @return string the top of the userContext stack
+   * Reads the top userContext stack.
    *
+   * @return string
+   *   the top of the userContext stack
    */
   public function readUserContext() {
     $this->createScope(self::USER_CONTEXT);
@@ -419,7 +425,7 @@ class CRM_Core_Session {
   }
 
   /**
-   * Dumps the session to the log
+   * Dumps the session to the log.
    * @param int $all
    */
   public function debug($all = 1) {
@@ -433,11 +439,13 @@ class CRM_Core_Session {
   }
 
   /**
-   * Fetches status messages
+   * Fetches status messages.
    *
-   * @param bool $reset should we reset the status variable?
+   * @param bool $reset
+   *   Should we reset the status variable?.
    *
-   * @return string        the status message if any
+   * @return string
+   *   the status message if any
    */
   public function getStatus($reset = FALSE) {
     $this->initialize();
@@ -456,13 +464,13 @@ class CRM_Core_Session {
   /**
    * 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'
@@ -471,7 +479,7 @@ class CRM_Core_Session {
    *               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)
@@ -479,7 +487,6 @@ class CRM_Core_Session {
    *                 defaults to 10 seconds for most messages, 5 if it has a title but no body,
    *                 or 0 for errors or messages containing links
    *
-   * @static
    *
    * @return void
    */
@@ -546,8 +553,9 @@ class CRM_Core_Session {
   }
 
   /**
-   * Retrieve contact id of the logged in user
-   * @return integer|NULL contact ID of logged in user
+   * Retrieve contact id of the logged in user.
+   * @return int|NULL
+   *   contact ID of logged in user
    */
   public static function getLoggedInContactID() {
     $session = CRM_Core_Session::singleton();
@@ -566,4 +574,5 @@ class CRM_Core_Session {
     // helps proxies like varnish
     return empty($_SESSION);
   }
+
 }