Source for file Session_Wrapper.php

Documentation is available at Session_Wrapper.php

  1. <?php   
  2. /* -------------------------------------------------------------------------- */
  3. /* Module      : Session_Wrapper                                              */
  4. /*                                                                            */
  5. /* Version History :                                                          */
  6. /*                                                                            */
  7. /* Date        Vsn     Author          Description                            */
  8. /* -------------------------------------------------------------------------- */
  9. /* 21/01/09    1.0     S.Lindo         Initial version.                       */
  10. /* -------------------------------------------------------------------------- */
  11. require_once("Zend/Session.php");   
  12. /**
  13.  * Singleton class.
  14.  * 
  15.  * @package Default
  16.  */
  17. class Session_Wrapper {   
  18.  
  19.     protected static $_instance;   
  20.     public $namespace = null;   
  21.   
  22.     private function __construct()
  23.     {
  24.         /* Create our Session namespace - using 'Default' namespace */  
  25.         $this->namespace = new Zend_Session_Namespace();   
  26.   
  27.         /** Check that our namespace has been initialized - if not,
  28.          * regenerate the session id. Makes Session fixation more difficult
  29.          * to achieve  
  30.          */  
  31.         if (!isset($this->namespace->initialized)) {   
  32.             Zend_Session::regenerateId();   
  33.             $this->namespace->initialized true;   
  34.         }   
  35.     }   
  36.   
  37.     /**  
  38.      * Implementation of the singleton design pattern
  39.      */  
  40.     public static function getInstance({   
  41.         if (null === self::$_instance{   
  42.             self::$_instance new self();   
  43.         }   
  44.   
  45.         return self::$_instance;   
  46.     }   
  47.   
  48.     /**  
  49.      * Public method to retrieve a value stored in the session
  50.      * return $default if $var not found in session namespace
  51.      * @param $var string
  52.      * @param $default string
  53.      * @return string 
  54.      */  
  55.     public function get($var$default=null){   
  56.         return (isset($this->namespace->$var)) $this->namespace->$var $default;   
  57.     }   
  58.   
  59.     /**  
  60.      * Public function to save a value to the session
  61.      * @param $var string
  62.      * @param $value 
  63.      */  
  64.     public function set($var$value=null){   
  65.         //if (!empty($var) && !empty($value)){   
  66.         if (!empty($var) ){   
  67.             $this->namespace->$var $value;   
  68.         }   
  69.     }   
  70.  
  71.     /**
  72.      * Clear out all session variables
  73.      * 
  74.      * @return void 
  75.      */
  76.     public function clearAll()
  77.     {
  78.         foreach ($this->namespace as $index => $value)
  79.         {
  80.             //unset($this->namespace->$index);
  81.             $this->namespace->$index null;
  82.         }
  83.     }   
  84.  
  85.  
  86.     /**
  87.      * Useful for debugging.
  88.      * 
  89.      * @return void 
  90.      * @todo Move this function to Debug (Action helper)
  91.      */
  92.     public function showAll()
  93.     {
  94.         foreach ($this->namespace as $index => $value)
  95.         {
  96.             if (is_array($value))
  97.             {
  98.                 echo "<BR>$index = \n";
  99.                 var_dump($value);
  100.             else {
  101.                 echo "<BR>$index = '$value';\n";
  102.             }
  103. //var_dump($value);
  104.         }
  105.  
  106.     }   
  107. }

Documentation generated on Fri, 27 Mar 2009 13:48:43 +0000 by phpDocumentor 1.4.1