1 <?php
2 /**
3 * Part of the Joomla Framework Session Package
4 *
5 * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE
7 */
8
9 namespace Joomla\Session\Storage;
10
11 use Joomla\Session\Storage;
12
13 /**
14 * Memcached session storage handler for PHP
15 *
16 * @since 1.0
17 * @deprecated 2.0 The Storage class chain will be removed
18 */
19 class Memcached extends Storage
20 {
21 /**
22 * Container for server data
23 *
24 * @var array
25 * @since 1.0
26 * @deprecated 2.0
27 */
28 protected $_servers = array();
29
30 /**
31 * Constructor
32 *
33 * @param array $options Optional parameters.
34 *
35 * @since 1.0
36 * @throws \RuntimeException
37 * @deprecated 2.0
38 */
39 public function __construct($options = array())
40 {
41 if (!self::isSupported())
42 {
43 throw new \RuntimeException('Memcached Extension is not available', 404);
44 }
45
46 // This will be an array of loveliness
47 // @todo: multiple servers
48 $this->_servers = array(
49 array(
50 'host' => isset($options['memcache_server_host']) ? $options['memcache_server_host'] : 'localhost',
51 'port' => isset($options['memcache_server_port']) ? $options['memcache_server_port'] : 11211
52 )
53 );
54
55 // Only construct parent AFTER host and port are sent, otherwise when register is called this will fail.
56 parent::__construct($options);
57 }
58
59 /**
60 * Register the functions of this class with PHP's session handler
61 *
62 * @return void
63 *
64 * @since 1.0
65 * @deprecated 2.0
66 */
67 public function register()
68 {
69 ini_set('session.save_path', $this->_servers[0]['host'] . ':' . $this->_servers[0]['port']);
70 ini_set('session.save_handler', 'memcached');
71 }
72
73 /**
74 * Test to see if the SessionHandler is available.
75 *
76 * @return boolean True on success, false otherwise.
77 *
78 * @since 1.0
79 * @deprecated 2.0
80 */
81 static public function isSupported()
82 {
83 /*
84 * GAE and HHVM have both had instances where Memcached the class was defined but no extension was loaded.
85 * If the class is there, we can assume it works.
86 */
87 return (class_exists('Memcached'));
88 }
89 }
90