HTTP_Session2
[ class tree: HTTP_Session2 ] [ index: HTTP_Session2 ] [ all elements ]

Source for file Container.php

Documentation is available at Container.php

  1. <?php
  2. //
  3. // +-----------------------------------------------------------------------+
  4. // | Copyright (c) 2004, Tony Bibbs                                        |
  5. // | All rights reserved.                                                  |
  6. // |                                                                       |
  7. // | Redistribution and use in source and binary forms, with or without    |
  8. // | modification, are permitted provided that the following conditions    |
  9. // | are met:                                                              |
  10. // |                                                                       |
  11. // | o Redistributions of source code must retain the above copyright      |
  12. // |   notice, this list of conditions and the following disclaimer.       |
  13. // | o Redistributions in binary form must reproduce the above copyright   |
  14. // |   notice, this list of conditions and the following disclaimer in the |
  15. // |   documentation and/or other materials provided with the distribution.|
  16. // | o The names of the authors may not be used to endorse or promote      |
  17. // |   products derived from this software without specific prior written  |
  18. // |   permission.                                                         |
  19. // |                                                                       |
  20. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
  21. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
  22. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  23. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
  24. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  25. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
  26. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  27. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  28. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
  29. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  30. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
  31. // |                                                                       |
  32. // +-----------------------------------------------------------------------+
  33. // | Author: Alexander Radivanovich <info@wwwlab.net>                      |
  34. // }         Tony Bibbs <tony@geeklog.net>                                 |
  35. // +-----------------------------------------------------------------------+
  36. //
  37.  
  38. require_once 'HTTP/Session2/ContainerInterface.php';
  39.  
  40. /**
  41.  * Container class for storing session data data
  42.  *
  43.  * @author  Alexander Radivaniovich <info@wwwlab.net>
  44.  * @package HTTP_Session2
  45.  * @access  public
  46.  */
  47. abstract class HTTP_Session2_Container implements HTTP_Session2_Container_Interface
  48. {
  49.     /**
  50.      * Additional options for the container object
  51.      *
  52.      * @var array 
  53.      * @access private
  54.      */
  55.     private $options = array();
  56.  
  57.     /**
  58.      * Constrtuctor method
  59.      *
  60.      * @access public
  61.      * @param  array  $options Additional options for the container object
  62.      * @return void 
  63.      */
  64.     public function __construct($options = null)
  65.     {
  66.         $this->setDefaults();
  67.         if (is_array($options)) {
  68.             $this->parseOptions();
  69.         }
  70.     }
  71.  
  72.     /**
  73.      * Set some default options
  74.      *
  75.      * @access private
  76.      */
  77.     private function setDefaults()
  78.     {
  79.     }
  80.  
  81.     /**
  82.      * Parse options passed to the container class
  83.      *
  84.      * @access protected
  85.      * @param array Options
  86.      */
  87.     protected function parseOptions($options)
  88.     {
  89.         foreach ($options as $option => $value{
  90.             if (in_array($optionarray_keys($this->options))) {
  91.                 $this->options[$option$value;
  92.             }
  93.         }
  94.         print_r($this->options); exit;
  95.     }
  96.  
  97.     /**
  98.      * Set session save handler
  99.      *
  100.      * @access public
  101.      * @return void 
  102.      */
  103.     public function set()
  104.     {
  105.         $GLOBALS['HTTP_Session2_Container'=$this;
  106.         session_module_name('user');
  107.         session_set_save_handler(
  108.             'HTTP_Session2_Open',
  109.             'HTTP_Session2_Close',
  110.             'HTTP_Session2_Read',
  111.             'HTTP_Session2_Write',
  112.             'HTTP_Session2_Destroy',
  113.             'HTTP_Session2_GC'
  114.         );
  115.     }
  116.  
  117. }
  118.  
  119. // Delegate function calls to the object's methods
  120. /** @ignore */
  121. function HTTP_Session2_Open($save_path$session_name
  122.     return $GLOBALS['HTTP_Session2_Container']->open($save_path$session_name)
  123. }
  124.  
  125. /** @ignore */
  126. function HTTP_Session2_Close()                         
  127.     return $GLOBALS['HTTP_Session2_Container']->close()
  128. }
  129.  
  130. /** @ignore */
  131. function HTTP_Session2_Read($id)                       
  132.     return $GLOBALS['HTTP_Session2_Container']->read($id)
  133.  
  134. }
  135.  
  136. /** @ignore */
  137. function HTTP_Session2_Write($id$data)               
  138.     return $GLOBALS['HTTP_Session2_Container']->write($id$data)
  139. }
  140.  
  141. /** @ignore */
  142. function HTTP_Session2_Destroy($id)                    
  143.     return $GLOBALS['HTTP_Session2_Container']->destroy($id)
  144. }
  145.  
  146. /** @ignore */
  147. function HTTP_Session2_GC($maxlifetime)                
  148.     return $GLOBALS['HTTP_Session2_Container']->gc($maxlifetime)
  149. }
  150.  
  151. session_set_save_handler('HTTP_Session2_Open',
  152.     'HTTP_Session2_Close',
  153.     'HTTP_Session2_Read',
  154.     'HTTP_Session2_Write',
  155.     'HTTP_Session2_Destroy',
  156.     'HTTP_Session2_GC');
  157. ?>

Documentation generated on Mon, 11 Mar 2019 14:18:38 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.