a few comment fixes
[civicrm-core.git] / CRM / Core / Session.php
index 446a5cd75357e86fefc14f28af9f54a4c8ab567a..ba1fe1b2a88bcdcbc342b53e8ff032503b8c857b 100644 (file)
@@ -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";
@@ -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
@@ -64,7 +64,6 @@ class CRM_Core_Session {
    * pattern and cache the instance in this variable
    *
    * @var object
-   * @static
    */
   static private $_singleton = NULL;
 
@@ -85,19 +84,18 @@ class CRM_Core_Session {
    *
    * @return CRM_Core_Session
    */
-  function __construct() {
-    $this->_session = null;
+  public function __construct() {
+    $this->_session = NULL;
   }
 
   /**
    * Singleton function used to manage this object
    *
    * @return CRM_Core_Session
-   * @static
    */
-  static function &singleton() {
+  public static function &singleton() {
     if (self::$_singleton === NULL) {
-      self::$_singleton = new CRM_Core_Session;
+      self::$_singleton = new CRM_Core_Session();
     }
     return self::$_singleton;
   }
@@ -106,13 +104,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)) {
@@ -125,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();
@@ -146,19 +144,18 @@ class CRM_Core_Session {
     ) {
       $this->_session[$this->_key] = array();
     }
-    return;
+    return NULL;
   }
 
   /**
    * 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();
 
@@ -170,20 +167,21 @@ class CRM_Core_Session {
       $this->_session = array();
     }
 
-    return;
+    return NULL;
   }
 
   /**
    * 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)) {
@@ -198,12 +196,12 @@ class CRM_Core_Session {
   /**
    * Resets the session local scope
    *
-   * @param string $prefix 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)) {
@@ -223,16 +221,17 @@ 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);
 
@@ -259,20 +258,20 @@ 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)) {
@@ -280,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];
     }
@@ -292,15 +291,15 @@ 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 $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
-   *
    */
-  function getVars(&$vars, $prefix = '') {
+  public function getVars(&$vars, $prefix = '') {
     // create session scope
     $this->createScope($prefix, TRUE);
 
@@ -324,35 +323,34 @@ 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;
     }
@@ -384,14 +382,12 @@ class CRM_Core_Session {
   /**
    * 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
-   *
-   * @access public
-   *
    */
-  function replaceUserContext($userContext) {
+  public function replaceUserContext($userContext) {
     if (empty($userContext)) {
       return;
     }
@@ -405,10 +401,10 @@ class CRM_Core_Session {
   /**
    * Pops the top userContext stack
    *
-   * @return string 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]);
@@ -417,10 +413,10 @@ class CRM_Core_Session {
   /**
    * Reads the top userContext stack
    *
-   * @return string 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();
@@ -432,7 +428,7 @@ 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);
@@ -445,11 +441,13 @@ class CRM_Core_Session {
   /**
    * 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
    */
-  function getStatus($reset = FALSE) {
+  public function getStatus($reset = FALSE) {
     $this->initialize();
 
     $status = NULL;
@@ -466,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'
@@ -481,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)
@@ -489,11 +487,10 @@ 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
    */
-  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,7 +522,7 @@ class CRM_Core_Session {
   /**
    * @param string|array $names
    */
-  static function registerAndRetrieveSessionObjects($names) {
+  public static function registerAndRetrieveSessionObjects($names) {
     if (!is_array($names)) {
       $names = array($names);
     }
@@ -543,7 +540,7 @@ class CRM_Core_Session {
   /**
    * @param bool $reset
    */
-  static function storeSessionObjects($reset = TRUE) {
+  public static function storeSessionObjects($reset = TRUE) {
     if (empty(self::$_managedNames)) {
       return;
     }
@@ -557,9 +554,10 @@ class CRM_Core_Session {
 
   /**
    * Retrieve contact id of the logged in user
-   * @return integer|NULL contact ID of logged in user
+   * @return int|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;
@@ -570,10 +568,11 @@ class CRM_Core_Session {
   /**
    * @return bool
    */
-  function isEmpty() {
+  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);
   }
+
 }