|
3 | 3 | namespaceSymfony\Bridge\Doctrine\HttpFoundation; |
4 | 4 |
|
5 | 5 | useDoctrine\DBAL\Platforms\MySqlPlatform; |
6 | | -useSymfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage; |
| 6 | +useSymfony\Component\HttpFoundation\AttributeBagInterface; |
| 7 | +useSymfony\Component\HttpFoundation\FlashBagInterface; |
| 8 | +useSymfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage; |
| 9 | +useSymfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface; |
7 | 10 | useDoctrine\DBAL\Driver\Connection; |
8 | 11 |
|
9 | 12 | /** |
|
12 | 15 | * @author Fabien Potencier <fabien@symfony.com> |
13 | 16 | * @author Johannes M. Schmitt <schmittjoh@gmail.com> |
14 | 17 | */ |
15 | | -class DbalSessionStorageextendsNativeSessionStorage |
| 18 | +class DbalSessionStorageextendsAbstractSessionStorageimplements SessionSaveHandlerInterface |
16 | 19 | { |
| 20 | +/** |
| 21 | + * @var Connection |
| 22 | + */ |
17 | 23 | private$con; |
| 24 | + |
| 25 | +/** |
| 26 | + * @var string |
| 27 | + */ |
18 | 28 | private$tableName; |
19 | 29 |
|
20 | | -publicfunction__construct(Connection$con,$tableName ='sessions',array$options =array()) |
| 30 | +/** |
| 31 | + * |
| 32 | + * @param Connection $con An instance of Connection. |
| 33 | + * @param string $tableName Table name. |
| 34 | + * @param array $options Session configuration options |
| 35 | + * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) |
| 36 | + * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) |
| 37 | + */ |
| 38 | +publicfunction__construct(Connection$con,$tableName ='sessions',array$options =array(),AttributeBagInterface$attributes =null,FlashBagInterface$flashes =null) |
21 | 39 | { |
22 | | -parent::__construct($options); |
23 | | - |
24 | 40 | $this->con =$con; |
25 | 41 | $this->tableName =$tableName; |
26 | | - } |
27 | | - |
28 | | -/** |
29 | | - * Starts the session. |
30 | | - */ |
31 | | -publicfunctionstart() |
32 | | - { |
33 | | -if (self::$sessionStarted) { |
34 | | -return; |
35 | | - } |
36 | 42 |
|
37 | | -// use this object as the session handler |
38 | | -session_set_save_handler( |
39 | | -array($this,'sessionOpen'), |
40 | | -array($this,'sessionClose'), |
41 | | -array($this,'sessionRead'), |
42 | | -array($this,'sessionWrite'), |
43 | | -array($this,'sessionDestroy'), |
44 | | -array($this,'sessionGC') |
45 | | - ); |
46 | | - |
47 | | -parent::start(); |
| 43 | +parent::__construct($attributes,$flashes,$options); |
48 | 44 | } |
49 | 45 |
|
50 | 46 | /** |
@@ -102,7 +98,7 @@ public function sessionDestroy($id) |
102 | 98 | * |
103 | 99 | * @throws \RuntimeException If any old sessions cannot be cleaned |
104 | 100 | */ |
105 | | -publicfunctionsessionGC($lifetime) |
| 101 | +publicfunctionsessionGc($lifetime) |
106 | 102 | { |
107 | 103 | try { |
108 | 104 | $this->con->executeQuery("DELETE FROM{$this->tableName} WHERE sess_time < :time",array( |
@@ -140,7 +136,7 @@ public function sessionRead($id) |
140 | 136 |
|
141 | 137 | return''; |
142 | 138 | }catch (\PDOException$e) { |
143 | | -thrownew \RuntimeException(sprintf('PDOException was thrown when trying tomanipulate session data: %s',$e->getMessage()),0,$e); |
| 139 | +thrownew \RuntimeException(sprintf('PDOException was thrown when trying toread the session data: %s',$e->getMessage()),0,$e); |
144 | 140 | } |
145 | 141 | } |
146 | 142 |
|
@@ -181,7 +177,7 @@ public function sessionWrite($id, $data) |
181 | 177 | $this->createNewSession($id,$data); |
182 | 178 | } |
183 | 179 | }catch (\PDOException$e) { |
184 | | -thrownew \RuntimeException(sprintf('PDOException was thrown when trying tomanipulate session data: %s',$e->getMessage()),0,$e); |
| 180 | +thrownew \RuntimeException(sprintf('PDOException was thrown when trying towrite the session data: %s',$e->getMessage()),0,$e); |
185 | 181 | } |
186 | 182 |
|
187 | 183 | returntrue; |
|