|
3 | 3 | namespace Symfony\Bridge\Doctrine\HttpFoundation;
|
4 | 4 |
|
5 | 5 | use Doctrine\DBAL\Platforms\MySqlPlatform;
|
6 |
| -use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage; |
| 6 | +use Symfony\Component\HttpFoundation\AttributeBagInterface; |
| 7 | +use Symfony\Component\HttpFoundation\FlashBagInterface; |
| 8 | +use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage; |
| 9 | +use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface; |
7 | 10 | use Doctrine\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 DbalSessionStorage extends NativeSessionStorage |
| 18 | +class DbalSessionStorage extends AbstractSessionStorage implements 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 |
| - public function __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 | + public function __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 |
| - public function start() |
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 |
| - public function sessionGC($lifetime) |
| 101 | + public function sessionGc($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 |
| - throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); |
| 139 | + throw new \RuntimeException(sprintf('PDOException was thrown when trying to read 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 |
| - throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); |
| 180 | + throw new \RuntimeException(sprintf('PDOException was thrown when trying to write the session data: %s', $e->getMessage()), 0, $e); |
185 | 181 | }
|
186 | 182 |
|
187 | 183 | return true;
|
|
0 commit comments