diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandler.php similarity index 59% rename from src/Symfony/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorage.php rename to src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandler.php index 3b91a077f5..d155052a97 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation\Session\Storage; +namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; /** * NativeRedisSessionStorage. @@ -20,37 +20,24 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; * * @author Andrej Hudec */ -class NativeRedisSessionStorage extends AbstractSessionStorage +class NativeRedisSessionHandler extends NativeSessionHandler { - /** - * @var string - */ - private $savePath; - /** * Constructor. * * @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')) { throw new \RuntimeException('PHP does not have "redis" session module registered'); } - $this->savePath = $savePath; - parent::__construct($options); - } + if (null === $savePath) { + $savePath = ini_get('session.save_path'); + } - /** - * {@inheritdoc} - */ - protected function registerSaveHandlers() - { ini_set('session.save_handler', 'redis'); - ini_set('session.save_path', $this->savePath); + ini_set('session.save_path', $savePath); } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandlerTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandlerTest.php new file mode 100644 index 0000000000..77ac423c51 --- /dev/null +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandlerTest.php @@ -0,0 +1,34 @@ +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')); + } +} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorageTest.php deleted file mode 100644 index 2a8a37503b..0000000000 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorageTest.php +++ /dev/null @@ -1,25 +0,0 @@ -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')); - } -} \ No newline at end of file