PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/session/storage/xcache.php

https://bitbucket.org/eternaware/joomus
PHP | 109 lines | 40 code | 11 blank | 58 comment | 3 complexity | b67430829846f996660572e325915721 MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Platform
  4 * @subpackage  Session
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE
  8 */
  9
 10defined('JPATH_PLATFORM') or die;
 11
 12/**
 13 * XCache session storage handler
 14 *
 15 * @package     Joomla.Platform
 16 * @subpackage  Session
 17 * @since       11.1
 18 */
 19class JSessionStorageXcache extends JSessionStorage
 20{
 21	/**
 22	 * Constructor
 23	 *
 24	 * @param   array  $options  Optional parameters.
 25	 *
 26	 * @since   11.1
 27	 * @throws  RuntimeException
 28	 */
 29	public function __construct($options = array())
 30	{
 31		if (!self::isSupported())
 32		{
 33			throw new RuntimeException('XCache Extension is not available', 404);
 34		}
 35
 36		parent::__construct($options);
 37	}
 38
 39	/**
 40	 * Read the data for a particular session identifier from the SessionHandler backend.
 41	 *
 42	 * @param   string  $id  The session identifier.
 43	 *
 44	 * @return  string  The session data.
 45	 *
 46	 * @since   11.1
 47	 */
 48	public function read($id)
 49	{
 50		$sess_id = 'sess_' . $id;
 51
 52		// Check if id exists
 53		if (!xcache_isset($sess_id))
 54		{
 55			return;
 56		}
 57
 58		return (string) xcache_get($sess_id);
 59	}
 60
 61	/**
 62	 * Write session data to the SessionHandler backend.
 63	 *
 64	 * @param   string  $id            The session identifier.
 65	 * @param   string  $session_data  The session data.
 66	 *
 67	 * @return  boolean  True on success, false otherwise.
 68	 *
 69	 * @since   11.1
 70	 */
 71	public function write($id, $session_data)
 72	{
 73		$sess_id = 'sess_' . $id;
 74		return xcache_set($sess_id, $session_data, ini_get("session.gc_maxlifetime"));
 75	}
 76
 77	/**
 78	 * Destroy the data for a particular session identifier in the SessionHandler backend.
 79	 *
 80	 * @param   string  $id  The session identifier.
 81	 *
 82	 * @return  boolean  True on success, false otherwise.
 83	 *
 84	 * @since   11.1
 85	 */
 86	public function destroy($id)
 87	{
 88		$sess_id = 'sess_' . $id;
 89
 90		if (!xcache_isset($sess_id))
 91		{
 92			return true;
 93		}
 94
 95		return xcache_unset($sess_id);
 96	}
 97
 98	/**
 99	 * Test to see if the SessionHandler is available.
100	 *
101	 * @return boolean  True on success, false otherwise.
102	 *
103	 * @since   12.1
104	 */
105	static public function isSupported()
106	{
107		return (extension_loaded('xcache'));
108	}
109}