Native Redis Session Storage update
This commit is contained in:
parent
665f59348b
commit
c4ee947a83
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeRedisSessionStorage.
|
* NativeRedisSessionStorage.
|
||||||
@ -20,37 +20,24 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @author Andrej Hudec <pulzarraider@gmail.com>
|
* @author Andrej Hudec <pulzarraider@gmail.com>
|
||||||
*/
|
*/
|
||||||
class NativeRedisSessionStorage extends AbstractSessionStorage
|
class NativeRedisSessionHandler extends NativeSessionHandler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $savePath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $savePath Path of redis server.
|
* @param string $savePath Path of redis server.
|
||||||
* @param array $options Session configuration options.
|
|
||||||
*
|
|
||||||
* @see AbstractSessionStorage::__construct()
|
|
||||||
*/
|
*/
|
||||||
public function __construct($savePath = 'tcp://127.0.0.1:6379?persistent=0', array $options = array())
|
public function __construct($savePath = 'tcp://127.0.0.1:6379?persistent=0')
|
||||||
{
|
{
|
||||||
if (!extension_loaded('redis')) {
|
if (!extension_loaded('redis')) {
|
||||||
throw new \RuntimeException('PHP does not have "redis" session module registered');
|
throw new \RuntimeException('PHP does not have "redis" session module registered');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->savePath = $savePath;
|
if (null === $savePath) {
|
||||||
parent::__construct($options);
|
$savePath = ini_get('session.save_path');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function registerSaveHandlers()
|
|
||||||
{
|
|
||||||
ini_set('session.save_handler', 'redis');
|
ini_set('session.save_handler', 'redis');
|
||||||
ini_set('session.save_path', $this->savePath);
|
ini_set('session.save_path', $savePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeRedisSessionHandler;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for NativeRedisSessionHandlerTest.
|
||||||
|
*
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class NativeRedisSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testSaveHandlers()
|
||||||
|
{
|
||||||
|
if (!extension_loaded('redis')) {
|
||||||
|
$this->markTestSkipped('Skipped tests Redis extension is not present');
|
||||||
|
}
|
||||||
|
|
||||||
|
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeRedisSessionHandler('tcp://127.0.0.1:6379?persistent=0'));
|
||||||
|
|
||||||
|
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||||
|
$this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
|
||||||
|
$this->assertEquals('redis', ini_get('session.save_handler'));
|
||||||
|
} else {
|
||||||
|
$this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
|
||||||
|
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals('tcp://127.0.0.1:6379?persistent=0', ini_get('session.save_path'));
|
||||||
|
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeRedisSessionStorage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for NativeRedisSessionStorage.
|
|
||||||
*
|
|
||||||
* @runTestsInSeparateProcesses
|
|
||||||
*/
|
|
||||||
class NativeRedisSessionStorageTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
public function testSaveHandlers()
|
|
||||||
{
|
|
||||||
if (!extension_loaded('redis')) {
|
|
||||||
$this->markTestSkipped('Skipped tests - Redis extension is not present');
|
|
||||||
}
|
|
||||||
|
|
||||||
$storage = new NativeRedisSessionStorage('tcp://127.0.0.1:6379?persistent=0', array('name' => 'TESTING'));
|
|
||||||
$this->assertEquals('redis', ini_get('session.save_handler'));
|
|
||||||
$this->assertEquals('tcp://127.0.0.1:6379?persistent=0', ini_get('session.save_path'));
|
|
||||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user