Skip to content

Commit c4ee947

Browse files
committed
Native Redis Session Storage update
1 parent 665f593 commit c4ee947

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorage.php renamed to src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeRedisSessionHandler.php

+7-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\HttpFoundation\Session\Storage;
12+
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
/**
1515
* NativeRedisSessionStorage.
@@ -20,37 +20,24 @@
2020
*
2121
* @author Andrej Hudec <pulzarraider@gmail.com>
2222
*/
23-
class NativeRedisSessionStorage extends AbstractSessionStorage
23+
class NativeRedisSessionHandler extends NativeSessionHandler
2424
{
25-
/**
26-
* @var string
27-
*/
28-
private $savePath;
29-
3025
/**
3126
* Constructor.
3227
*
3328
* @param string $savePath Path of redis server.
34-
* @param array $options Session configuration options.
35-
*
36-
* @see AbstractSessionStorage::__construct()
3729
*/
38-
public function __construct($savePath = 'tcp://127.0.0.1:6379?persistent=0', array $options = array())
30+
public function __construct($savePath = 'tcp://127.0.0.1:6379?persistent=0')
3931
{
4032
if (!extension_loaded('redis')) {
4133
throw new \RuntimeException('PHP does not have "redis" session module registered');
4234
}
4335

44-
$this->savePath = $savePath;
45-
parent::__construct($options);
46-
}
36+
if (null === $savePath) {
37+
$savePath = ini_get('session.save_path');
38+
}
4739

48-
/**
49-
* {@inheritdoc}
50-
*/
51-
protected function registerSaveHandlers()
52-
{
5340
ini_set('session.save_handler', 'redis');
54-
ini_set('session.save_path', $this->savePath);
41+
ini_set('session.save_path', $savePath);
5542
}
5643
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
4+
5+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeRedisSessionHandler;
6+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
7+
8+
/**
9+
* Test class for NativeRedisSessionHandlerTest.
10+
*
11+
* @runTestsInSeparateProcesses
12+
*/
13+
class NativeRedisSessionHandlerTest extends \PHPUnit_Framework_TestCase
14+
{
15+
public function testSaveHandlers()
16+
{
17+
if (!extension_loaded('redis')) {
18+
$this->markTestSkipped('Skipped tests Redis extension is not present');
19+
}
20+
21+
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeRedisSessionHandler('tcp://127.0.0.1:6379?persistent=0'));
22+
23+
if (version_compare(phpversion(), '5.4.0', '<')) {
24+
$this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
25+
$this->assertEquals('redis', ini_get('session.save_handler'));
26+
} else {
27+
$this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
28+
$this->assertEquals('user', ini_get('session.save_handler'));
29+
}
30+
31+
$this->assertEquals('tcp://127.0.0.1:6379?persistent=0', ini_get('session.save_path'));
32+
$this->assertEquals('TESTING', ini_get('session.name'));
33+
}
34+
}

tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeRedisSessionStorageTest.php

-25
This file was deleted.

0 commit comments

Comments
 (0)