1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Session
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * XCache session storage handler
14 *
15 * @since 11.1
16 * @deprecated 4.0 The CMS' Session classes will be replaced with the `joomla/session` package
17 */
18 class JSessionStorageXcache extends JSessionStorage
19 {
20 /**
21 * Constructor
22 *
23 * @param array $options Optional parameters.
24 *
25 * @since 11.1
26 * @throws RuntimeException
27 */
28 public function __construct($options = array())
29 {
30 if (!self::isSupported())
31 {
32 throw new RuntimeException('XCache Extension is not available', 404);
33 }
34
35 parent::__construct($options);
36 }
37
38 /**
39 * Read the data for a particular session identifier from the SessionHandler backend.
40 *
41 * @param string $id The session identifier.
42 *
43 * @return string The session data.
44 *
45 * @since 11.1
46 */
47 public function read($id)
48 {
49 $sess_id = 'sess_' . $id;
50
51 // Check if id exists
52 if (!xcache_isset($sess_id))
53 {
54 return;
55 }
56
57 return (string) xcache_get($sess_id);
58 }
59
60 /**
61 * Write session data to the SessionHandler backend.
62 *
63 * @param string $id The session identifier.
64 * @param string $session_data The session data.
65 *
66 * @return boolean True on success, false otherwise.
67 *
68 * @since 11.1
69 */
70 public function write($id, $session_data)
71 {
72 $sess_id = 'sess_' . $id;
73
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 public static function isSupported()
106 {
107 return extension_loaded('xcache');
108 }
109 }
110