INFRA-132 - @param type fixes
[civicrm-core.git] / CRM / Core / Session.php
index 676b24065654321db490afef718e17c5c0ef36c3..6bc89eb9f2d168dc4e07c04cdd15023c0986921f 100644 (file)
@@ -49,7 +49,7 @@ class CRM_Core_Session {
    * @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
@@ -71,22 +71,22 @@ class CRM_Core_Session {
   /**
    * 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;
   }
 
   /**
@@ -95,7 +95,7 @@ class CRM_Core_Session {
    * @return CRM_Core_Session
    * @static
    */
-  static function &singleton() {
+  public static function &singleton() {
     if (self::$_singleton === NULL) {
       self::$_singleton = new CRM_Core_Session;
     }
@@ -106,13 +106,13 @@ 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.
    *
-   * @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)) {
@@ -122,9 +122,10 @@ class CRM_Core_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();
@@ -151,13 +152,12 @@ class CRM_Core_Session {
   /**
    * 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();
 
@@ -175,14 +175,15 @@ class CRM_Core_Session {
   /**
    * 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)) {
@@ -197,12 +198,12 @@ class CRM_Core_Session {
   /**
    * 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)) {
@@ -222,16 +223,18 @@ class CRM_Core_Session {
    * 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);
 
@@ -258,20 +261,21 @@ class CRM_Core_Session {
    * 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)) {
@@ -279,7 +283,7 @@ class CRM_Core_Session {
     }
     else {
       if (empty($this->_session[$this->_key][$prefix])) {
-        return null;
+        return NULL;
       }
       $session =& $this->_session[$this->_key][$prefix];
     }
@@ -291,15 +295,16 @@ class CRM_Core_Session {
    * 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);
 
@@ -323,35 +328,37 @@ class CRM_Core_Session {
    * 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;
     }
@@ -383,14 +390,14 @@ class CRM_Core_Session {
   /**
    * 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;
     }
@@ -404,12 +411,10 @@ class CRM_Core_Session {
   /**
    * 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]);
@@ -418,12 +423,10 @@ class CRM_Core_Session {
   /**
    * 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();
@@ -433,8 +436,9 @@ class CRM_Core_Session {
 
   /**
    * 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);
@@ -447,11 +451,12 @@ class CRM_Core_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;
@@ -468,13 +473,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'
@@ -483,7 +488,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)
@@ -495,7 +500,7 @@ class CRM_Core_Session {
    *
    * @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();
@@ -525,9 +530,9 @@ class CRM_Core_Session {
   }
 
   /**
-   * @param string $names
+   * @param string|array $names
    */
-  static function registerAndRetrieveSessionObjects($names) {
+  public static function registerAndRetrieveSessionObjects($names) {
     if (!is_array($names)) {
       $names = array($names);
     }
@@ -545,7 +550,7 @@ class CRM_Core_Session {
   /**
    * @param bool $reset
    */
-  static function storeSessionObjects($reset = TRUE) {
+  public static function storeSessionObjects($reset = TRUE) {
     if (empty(self::$_managedNames)) {
       return;
     }
@@ -559,9 +564,9 @@ class CRM_Core_Session {
 
   /**
    * 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;
@@ -572,10 +577,10 @@ class CRM_Core_Session {
   /**
    * @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);
   }
 }