File tree 2 files changed +81
-0
lines changed
src/Symfony/Component/HttpFoundation/Session/Storage
tests/Symfony/Tests/Component/HttpFoundation/Session/Storage
2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \HttpFoundation \Session \Storage ;
13
+
14
+ /**
15
+ * NativeRedisSessionStorage.
16
+ *
17
+ * Driver for the redis session save hadlers provided by the redis PHP extension.
18
+ *
19
+ * @see https://github.com/nicolasff/phpredis
20
+ *
21
+ * @author Andrej Hudec <pulzarraider@gmail.com>
22
+ */
23
+ class NativeRedisSessionStorage extends AbstractSessionStorage
24
+ {
25
+ /**
26
+ * @var string
27
+ */
28
+ private $ savePath ;
29
+
30
+ /**
31
+ * Constructor.
32
+ *
33
+ * @param string $savePath Path of redis server.
34
+ * @param array $options Session configuration options.
35
+ *
36
+ * @see AbstractSessionStorage::__construct()
37
+ */
38
+ public function __construct ($ savePath = 'tcp://127.0.0.1:6379?persistent=0 ' , array $ options = array ())
39
+ {
40
+ if (!extension_loaded ('redis ' )) {
41
+ throw new \RuntimeException ('PHP does not have "redis" session module registered ' );
42
+ }
43
+
44
+ $ this ->savePath = $ savePath ;
45
+ parent ::__construct ($ options );
46
+ }
47
+
48
+ /**
49
+ * {@inheritdoc}
50
+ */
51
+ protected function registerSaveHandlers ()
52
+ {
53
+ ini_set ('session.save_handler ' , 'redis ' );
54
+ ini_set ('session.save_path ' , $ this ->savePath );
55
+ }
56
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Tests \Component \HttpFoundation \Session \Storage ;
4
+
5
+ use Symfony \Component \HttpFoundation \Session \Storage \NativeRedisSessionStorage ;
6
+
7
+ /**
8
+ * Test class for NativeRedisSessionStorage.
9
+ *
10
+ * @runTestsInSeparateProcesses
11
+ */
12
+ class NativeRedisSessionStorageTest extends \PHPUnit_Framework_TestCase
13
+ {
14
+ public function testSaveHandlers ()
15
+ {
16
+ if (!extension_loaded ('redis ' )) {
17
+ $ this ->markTestSkipped ('Skipped tests - Redis extension is not present ' );
18
+ }
19
+
20
+ $ storage = new NativeRedisSessionStorage ('tcp://127.0.0.1:6379?persistent=0 ' , array ('name ' => 'TESTING ' ));
21
+ $ this ->assertEquals ('redis ' , ini_get ('session.save_handler ' ));
22
+ $ this ->assertEquals ('tcp://127.0.0.1:6379?persistent=0 ' , ini_get ('session.save_path ' ));
23
+ $ this ->assertEquals ('TESTING ' , ini_get ('session.name ' ));
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments