Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/environment/sessionstorage.php

Documentation is available at sessionstorage.php

  1. <?php
  2. /**
  3. @version        $Id: session.php 6157 2007-01-03 00:22:09Z Jinx $
  4. @package        Joomla.Framework
  5. @subpackage    Environment
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19. * Custom session storage handler for PHP
  20. *
  21. @abstract
  22. @author        Johan Janssens <[email protected]>
  23. @package        Joomla.Framework
  24. @subpackage    Environment
  25. @since        1.5
  26. @see http://www.php.net/manual/en/function.session-set-save-handler.php
  27. */
  28. class JSessionStorage extends JObject
  29. {
  30.     /**
  31.     * Constructor
  32.     *
  33.     * @access protected
  34.     * @param array $options optional parameters
  35.     */
  36.     function __construct$options array() )
  37.     {
  38.         $this->register($options);
  39.     }
  40.  
  41.     /**
  42.      * Returns a reference to a session storage handler object, only creating it
  43.      * if it doesn't already exist.
  44.      *
  45.      * @access public
  46.      * @param name     $name The session store to instantiate
  47.      * @return database A JSessionStorage object
  48.      * @since 1.5
  49.      */
  50.     function &getInstance($name 'none'$options array())
  51.     {
  52.         static $instances;
  53.  
  54.         if (!isset ($instances)) {
  55.             $instances array ();
  56.         }
  57.  
  58.         $handler strtolower($name);
  59.         if (empty ($instances[$name]))
  60.         {
  61.             jimport('joomla.environment.sessionstorage.'.$name);
  62.             $class 'JSessionStorage'.ucfirst($name);
  63.             $instances[$namenew $class($options);
  64.         }
  65.  
  66.         return $instances[$name];
  67.     }
  68.  
  69.     /**
  70.     * Register the functions of this class with PHP's session handler
  71.     *
  72.     * @access public
  73.     * @param array $options optional parameters
  74.     */
  75.     function register$options array() )
  76.     {
  77.         // use this object as the session handler
  78.         session_set_save_handler(
  79.             array($this'open'),
  80.             array($this'close'),
  81.             array($this'read'),
  82.             array($this'write'),
  83.             array($this'destroy'),
  84.             array($this'gc')
  85.         );
  86.     }
  87.  
  88.     /**
  89.      * Open the SessionHandler backend.
  90.      *
  91.      * @abstract
  92.      * @access public
  93.      * @param string $save_path     The path to the session object.
  94.      * @param string $session_name  The name of the session.
  95.      * @return boolean  True on success, false otherwise.
  96.      */
  97.     function open($save_path$session_name)
  98.     {
  99.         return true;
  100.     }
  101.  
  102.     /**
  103.      * Close the SessionHandler backend.
  104.      *
  105.      * @abstract
  106.      * @access public
  107.      * @return boolean  True on success, false otherwise.
  108.      */
  109.     function close()
  110.     {
  111.         return true;
  112.     }
  113.  
  114.      /**
  115.       * Read the data for a particular session identifier from the
  116.       * SessionHandler backend.
  117.       *
  118.       * @abstract
  119.       * @access public
  120.       * @param string $id  The session identifier.
  121.       * @return string  The session data.
  122.       */
  123.     function read($id)
  124.     {
  125.         return;
  126.     }
  127.  
  128.     /**
  129.      * Write session data to the SessionHandler backend.
  130.      *
  131.      * @abstract
  132.      * @access public
  133.      * @param string $id            The session identifier.
  134.      * @param string $session_data  The session data.
  135.      * @return boolean  True on success, false otherwise.
  136.      */
  137.     function write($id$session_data)
  138.     {
  139.         return true;
  140.     }
  141.  
  142.     /**
  143.       * Destroy the data for a particular session identifier in the
  144.       * SessionHandler backend.
  145.       *
  146.       * @abstract
  147.       * @access public
  148.       * @param string $id  The session identifier.
  149.       * @return boolean  True on success, false otherwise.
  150.       */
  151.     function destroy($id)
  152.     {
  153.         return true;
  154.     }
  155.  
  156.     /**
  157.      * Garbage collect stale sessions from the SessionHandler backend.
  158.      *
  159.      * @abstract
  160.      * @access public
  161.      * @param integer $maxlifetime  The maximum age of a session.
  162.      * @return boolean  True on success, false otherwise.
  163.      */
  164.     function gc($maxlifetime)
  165.     {
  166.         return true;
  167.     }
  168.  
  169.     /**
  170.      * Test to see if the SessionHandler is available.
  171.      *
  172.      * @abstract
  173.      * @static
  174.      * @access public
  175.      * @return boolean  True on success, false otherwise.
  176.      */
  177.     function test()
  178.     {
  179.         return true;
  180.     }
  181. }
  182. ?>

Documentation generated on Mon, 05 Mar 2007 21:21:42 +0000 by phpDocumentor 1.3.1