- md5
- 38bbd42a6252a8f3a5c80170d2f44892
- sha1
- f906e7dd1e5dee166a4847da87e674c4a88cd98a
- sha256
- 4c78ff400a31e00dd4c453d242834f38030a65ca22ee588aee515e183e64f23d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
<?php
/**
* @package Joomla.Libraries
* @subpackage Service
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\Service\Provider;
defined('JPATH_PLATFORM') or die;
use InvalidArgumentException;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Session\Storage\JoomlaStorage;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Session\Handler;
use Joomla\Session\Storage\RuntimeStorage;
use Joomla\Session\Validator\AddressValidator;
use Joomla\Session\Validator\ForwardedValidator;
use Memcached;
use Redis;
use RuntimeException;
/**
* Service provider for the application's session dependency
*
* @since 4.0
*/
class Session implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0
*/
public function register(Container $container)
{
$container->alias('session', 'Joomla\Session\SessionInterface')
->alias('JSession', 'Joomla\Session\SessionInterface')
->alias('Joomla\Session\Session', 'Joomla\Session\SessionInterface')
->share(
'Joomla\Session\SessionInterface',
function (Container $container)
{
$config = Factory::getConfig();
$app = Factory::getApplication();
// Generate a session name.
$name = ApplicationHelper::getHash($config->get('session_name', get_class($app)));
// Calculate the session lifetime.
$lifetime = (($config->get('lifetime')) ? $config->get('lifetime') * 60 : 900);
// Initialize the options for the Session object.
$options = array(
'name' => $name,
'expire' => $lifetime
);
if ($app->isClient('site') && $config->get('force_ssl') == 2)
{
$options['force_ssl'] = true;
}
if ($app->isClient('administrator') && $config->get('force_ssl') >= 1)
{
$options['force_ssl'] = true;
}
// Set up the storage handler
$handlerType = $config->get('session_handler', 'filesystem');
switch ($handlerType)
{
case 'apcu':
if (!Handler\ApcuHandler::isSupported())
{
throw new RuntimeException('APCu is not supported on this system.');
}
$handler = new Handler\ApcuHandler;
break;
case 'database':
$handler = new Handler\DatabaseHandler(Factory::getDbo());
break;
case 'filesystem':
case 'none':
$path = $config->get('session_filesystem_path', '');
// If no path is given, fall back to the system's temporary directory
if (empty($path))
{
$path = sys_get_temp_dir();
}
$handler = new Handler\FilesystemHandler($path);
break;
case 'memcached':
if (!Handler\MemcachedHandler::isSupported())
{
throw new RuntimeException('Memcached is not supported on this system.');
}
$host = $config->get('session_memcached_server_host', 'localhost');
$port = $config->get('session_memcached_server_port', 11211);
$memcached = new Memcached($config->get('session_memcached_server_id', 'joomla_cms'));
$memcached->addServer($host, $port);
$handler = new Handler\MemcachedHandler($memcached, array('ttl' => $lifetime));
ini_set('session.save_path', "$host:$port");
ini_set('session.save_handler', 'memcached');
break;
case 'redis':
if (!Handler\RedisHandler::isSupported())
{
throw new RuntimeException('Redis is not supported on this system.');
}
$redis = new Redis;
$redis->connect(
$config->get('session_redis_server_host', '127.0.0.1'),
$config->get('session_redis_server_port', 6379)
);
$handler = new Handler\RedisHandler($redis, array('ttl' => $lifetime));
break;
case 'wincache':
if (!Handler\WincacheHandler::isSupported())
{
throw new RuntimeException('Wincache is not supported on this system.');
}
$handler = new Handler\WincacheHandler;
break;
case 'xcache':
if (!Handler\XCacheHandler::isSupported())
{
throw new RuntimeException('XCache is not supported on this system.');
}
$handler = new Handler\XCacheHandler;
break;
default:
throw new InvalidArgumentException(sprintf('The "%s" session handler is not recognised.', $handlerType));
}
$input = $app->input;
if ($app->isClient('cli'))
{
$storage = new RuntimeStorage;
}
else
{
$storage = new JoomlaStorage($input, $handler);
}
$dispatcher = $container->get('Joomla\Event\DispatcherInterface');
if (method_exists($app, 'afterSessionStart'))
{
$dispatcher->addListener('onAfterSessionStart', array($app, 'afterSessionStart'));
}
$session = new \Joomla\CMS\Session\Session($storage, $dispatcher, $options);
$session->addValidator(new AddressValidator($input, $session));
$session->addValidator(new ForwardedValidator($input, $session));
return $session;
},
true
);
}
}
No other release has this exact content. See every version of this file.