PageRenderTime 11ms CodeModel.GetById 8ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/vendor/joomla/session/Joomla/Session/Storage/Memcache.php

https://gitlab.com/vitaliylukin91/idea-rating
PHP | 72 lines | 29 code | 7 blank | 36 comment | 2 complexity | de98f5e708e3a1188775e8baadab8ed7 MD5 | raw file
 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
 9namespace Joomla\Session\Storage;
10
11use Joomla\Session\Storage;
12
13/**
14 * Memcache session storage handler for PHP
15 *
16 * @since  1.0
17 * @deprecated  The joomla/session package is deprecated
18 */
19class Memcache extends Storage
20{
21	/**
22	 * Constructor
23	 *
24	 * @param   array  $options  Optional parameters.
25	 *
26	 * @since   1.0
27	 * @throws  \RuntimeException
28	 */
29	public function __construct($options = array())
30	{
31		if (!self::isSupported())
32		{
33			throw new \RuntimeException('Memcache Extension is not available', 404);
34		}
35
36		parent::__construct($options);
37
38		// This will be an array of loveliness
39		// @todo: multiple servers
40		$this->_servers = array(
41			array(
42				'host' => isset($options['memcache_server_host']) ? $options['memcache_server_host'] : 'localhost',
43				'port' => isset($options['memcache_server_port']) ? $options['memcache_server_port'] : 11211
44			)
45		);
46	}
47
48	/**
49	 * Register the functions of this class with PHP's session handler
50	 *
51	 * @return  void
52	 *
53	 * @since   1.0
54	 */
55	public function register()
56	{
57		ini_set('session.save_path', $this->_servers[0]['host'] . ':' . $this->_servers[0]['port']);
58		ini_set('session.save_handler', 'memcache');
59	}
60
61	/**
62	 * Test to see if the SessionHandler is available.
63	 *
64	 * @return boolean  True on success, false otherwise.
65	 *
66	 * @since   1.0
67	 */
68	static public function isSupported()
69	{
70		return (extension_loaded('memcache') && class_exists('Memcache'));
71	}
72}