You've already forked joomla_test
first commit
This commit is contained in:
1
libraries/joomla/session/index.html
Normal file
1
libraries/joomla/session/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
1009
libraries/joomla/session/session.php
Normal file
1009
libraries/joomla/session/session.php
Normal file
File diff suppressed because it is too large
Load Diff
208
libraries/joomla/session/storage.php
Normal file
208
libraries/joomla/session/storage.php
Normal file
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Custom session storage handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @see http://www.php.net/manual/en/function.session-set-save-handler.php
|
||||
* @todo When dropping compatibility with PHP 5.3 use the SessionHandlerInterface and the SessionHandler class
|
||||
* @since 11.1
|
||||
*/
|
||||
abstract class JSessionStorage
|
||||
{
|
||||
/**
|
||||
* @var array JSessionStorage instances container.
|
||||
* @since 11.3
|
||||
*/
|
||||
protected static $instances = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Optional parameters.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
$this->register($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a session storage handler object, only creating it if it doesn't already exist.
|
||||
*
|
||||
* @param string $name The session store to instantiate
|
||||
* @param array $options Array of options
|
||||
*
|
||||
* @return JSessionStorage
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function getInstance($name = 'none', $options = array())
|
||||
{
|
||||
$name = strtolower(JFilterInput::getInstance()->clean($name, 'word'));
|
||||
|
||||
if (empty(self::$instances[$name]))
|
||||
{
|
||||
$class = 'JSessionStorage' . ucfirst($name);
|
||||
|
||||
if (!class_exists($class))
|
||||
{
|
||||
$path = __DIR__ . '/storage/' . $name . '.php';
|
||||
|
||||
if (file_exists($path))
|
||||
{
|
||||
require_once $path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No attempt to die gracefully here, as it tries to close the non-existing session
|
||||
jexit('Unable to load session storage class: ' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
self::$instances[$name] = new $class($options);
|
||||
}
|
||||
|
||||
return self::$instances[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the functions of this class with PHP's session handler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Use this object as the session handler
|
||||
session_set_save_handler(
|
||||
array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'),
|
||||
array($this, 'destroy'), array($this, 'gc')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the SessionHandler backend.
|
||||
*
|
||||
* @param string $save_path The path to the session object.
|
||||
* @param string $session_name The name of the session.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function open($save_path, $session_name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the SessionHandler backend.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data for a particular session identifier from the
|
||||
* SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return string The session data.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write session data to the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
* @param string $session_data The session data.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function write($id, $session_data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the data for a particular session identifier in the
|
||||
* SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Garbage collect stale sessions from the SessionHandler backend.
|
||||
*
|
||||
* @param integer $maxlifetime The maximum age of a session.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function gc($maxlifetime = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
* @deprecated 12.3 (Platform) & 4.0 (CMS) - Use JSessionStorage::isSupported() instead.
|
||||
*/
|
||||
public static function test()
|
||||
{
|
||||
JLog::add('JSessionStorage::test() is deprecated. Use JSessionStorage::isSupported() instead.', JLog::WARNING, 'deprecated');
|
||||
|
||||
return static::isSupported();
|
||||
}
|
||||
}
|
98
libraries/joomla/session/storage/apc.php
Normal file
98
libraries/joomla/session/storage/apc.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* APC session storage handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @see http://www.php.net/manual/en/function.session-set-save-handler.php
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageApc extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Optional parameters
|
||||
*
|
||||
* @since 11.1
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (!self::isSupported())
|
||||
{
|
||||
throw new RuntimeException('APC Extension is not available', 404);
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data for a particular session identifier from the
|
||||
* SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return string The session data.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
$sess_id = 'sess_' . $id;
|
||||
return (string) apc_fetch($sess_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write session data to the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
* @param string $session_data The session data.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function write($id, $session_data)
|
||||
{
|
||||
$sess_id = 'sess_' . $id;
|
||||
return apc_store($sess_id, $session_data, ini_get("session.gc_maxlifetime"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the data for a particular session identifier in the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$sess_id = 'sess_' . $id;
|
||||
return apc_delete($sess_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return extension_loaded('apc');
|
||||
}
|
||||
}
|
165
libraries/joomla/session/storage/database.php
Normal file
165
libraries/joomla/session/storage/database.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Database session storage handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @see http://www.php.net/manual/en/function.session-set-save-handler.php
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageDatabase extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Read the data for a particular session identifier from the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return string The session data.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
// Get the database connection object and verify its connected.
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
try
|
||||
{
|
||||
// Get the session data from the database table.
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('data'))
|
||||
->from($db->quoteName('#__session'))
|
||||
->where($db->quoteName('session_id') . ' = ' . $db->quote($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$result = (string) $db->loadResult();
|
||||
|
||||
$result = str_replace('\0\0\0', chr(0) . '*' . chr(0), $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write session data to the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
* @param string $data The session data.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function write($id, $data)
|
||||
{
|
||||
// Get the database connection object and verify its connected.
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$data = str_replace(chr(0) . '*' . chr(0), '\0\0\0', $data);
|
||||
|
||||
try
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__session'))
|
||||
->set($db->quoteName('data') . ' = ' . $db->quote($data))
|
||||
->set($db->quoteName('time') . ' = ' . $db->quote((int) time()))
|
||||
->where($db->quoteName('session_id') . ' = ' . $db->quote($id));
|
||||
|
||||
// Try to update the session data in the database table.
|
||||
$db->setQuery($query);
|
||||
if (!$db->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/* Since $db->execute did not throw an exception, so the query was successful.
|
||||
Either the data changed, or the data was identical.
|
||||
In either case we are done.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the data for a particular session identifier in the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
// Get the database connection object and verify its connected.
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
try
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__session'))
|
||||
->where($db->quoteName('session_id') . ' = ' . $db->quote($id));
|
||||
|
||||
// Remove a session from the database.
|
||||
$db->setQuery($query);
|
||||
|
||||
return (boolean) $db->execute();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Garbage collect stale sessions from the SessionHandler backend.
|
||||
*
|
||||
* @param integer $lifetime The maximum age of a session.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function gc($lifetime = 1440)
|
||||
{
|
||||
// Get the database connection object and verify its connected.
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
// Determine the timestamp threshold with which to purge old sessions.
|
||||
$past = time() - $lifetime;
|
||||
|
||||
try
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__session'))
|
||||
->where($db->quoteName('time') . ' < ' . $db->quote((int) $past));
|
||||
|
||||
// Remove expired sessions from the database.
|
||||
$db->setQuery($query);
|
||||
|
||||
return (boolean) $db->execute();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
1
libraries/joomla/session/storage/index.html
Normal file
1
libraries/joomla/session/storage/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
74
libraries/joomla/session/storage/memcache.php
Normal file
74
libraries/joomla/session/storage/memcache.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Memcache session storage handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageMemcache extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Optional parameters.
|
||||
*
|
||||
* @since 11.1
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (!self::isSupported())
|
||||
{
|
||||
throw new RuntimeException('Memcache Extension is not available', 404);
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
|
||||
// This will be an array of loveliness
|
||||
// @todo: multiple servers
|
||||
$this->_servers = array(
|
||||
array(
|
||||
'host' => $config->get('memcache_server_host', 'localhost'),
|
||||
'port' => $config->get('memcache_server_port', 11211)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the functions of this class with PHP's session handler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 12.2
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
ini_set('session.save_path', $this->_servers['host'] . ':' . $this->_servers['port']);
|
||||
ini_set('session.save_handler', 'memcache');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
static public function isSupported()
|
||||
{
|
||||
return (extension_loaded('memcache') && class_exists('Memcache'));
|
||||
}
|
||||
}
|
74
libraries/joomla/session/storage/memcached.php
Normal file
74
libraries/joomla/session/storage/memcached.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Memcached session storage handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageMemcached extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Optional parameters.
|
||||
*
|
||||
* @since 11.1
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (!self::isSupported())
|
||||
{
|
||||
throw new RuntimeException('Memcached Extension is not available', 404);
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
|
||||
// This will be an array of loveliness
|
||||
// @todo: multiple servers
|
||||
$this->_servers = array(
|
||||
array(
|
||||
'host' => $config->get('memcache_server_host', 'localhost'),
|
||||
'port' => $config->get('memcache_server_port', 11211)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the functions of this class with PHP's session handler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 12.2
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
ini_set('session.save_path', $this->_servers['host'] . ':' . $this->_servers['port']);
|
||||
ini_set('session.save_handler', 'memcached');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
static public function isSupported()
|
||||
{
|
||||
return (extension_loaded('memcached') && class_exists('Memcached'));
|
||||
}
|
||||
}
|
33
libraries/joomla/session/storage/none.php
Normal file
33
libraries/joomla/session/storage/none.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* File session handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @see http://www.php.net/manual/en/function.session-set-save-handler.php
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageNone extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Register the functions of this class with PHP's session handler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
ini_set('session.save_handler', 'files');
|
||||
}
|
||||
}
|
62
libraries/joomla/session/storage/wincache.php
Normal file
62
libraries/joomla/session/storage/wincache.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* WINCACHE session storage handler for PHP
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageWincache extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Optional parameters.
|
||||
*
|
||||
* @since 11.1
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (!self::isSupported())
|
||||
{
|
||||
throw new RuntimeException('Wincache Extension is not available', 404);
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the functions of this class with PHP's session handler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 12.2
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
ini_set('session.save_handler', 'wincache');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
static public function isSupported()
|
||||
{
|
||||
return (extension_loaded('wincache') && function_exists('wincache_ucache_get') && !strcmp(ini_get('wincache.ucenabled'), "1"));
|
||||
}
|
||||
}
|
109
libraries/joomla/session/storage/xcache.php
Normal file
109
libraries/joomla/session/storage/xcache.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* XCache session storage handler
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Session
|
||||
* @since 11.1
|
||||
*/
|
||||
class JSessionStorageXcache extends JSessionStorage
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Optional parameters.
|
||||
*
|
||||
* @since 11.1
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (!self::isSupported())
|
||||
{
|
||||
throw new RuntimeException('XCache Extension is not available', 404);
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data for a particular session identifier from the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return string The session data.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
$sess_id = 'sess_' . $id;
|
||||
|
||||
// Check if id exists
|
||||
if (!xcache_isset($sess_id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return (string) xcache_get($sess_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write session data to the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
* @param string $session_data The session data.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function write($id, $session_data)
|
||||
{
|
||||
$sess_id = 'sess_' . $id;
|
||||
return xcache_set($sess_id, $session_data, ini_get("session.gc_maxlifetime"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the data for a particular session identifier in the SessionHandler backend.
|
||||
*
|
||||
* @param string $id The session identifier.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$sess_id = 'sess_' . $id;
|
||||
|
||||
if (!xcache_isset($sess_id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return xcache_unset($sess_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the SessionHandler is available.
|
||||
*
|
||||
* @return boolean True on success, false otherwise.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
static public function isSupported()
|
||||
{
|
||||
return (extension_loaded('xcache'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user