Skip to content

Commit 1ed6ee3

Browse files
author
Drak
committed
[DoctribeBridge][SecurityBundle][WebProfiler] Refactor code for HttpFoundation changes.
1 parent 7aaf024 commit 1ed6ee3

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php

+25-29
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace Symfony\Bridge\Doctrine\HttpFoundation;
44

55
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;
710
use Doctrine\DBAL\Driver\Connection;
811

912
/**
@@ -12,39 +15,32 @@
1215
* @author Fabien Potencier <fabien@symfony.com>
1316
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
1417
*/
15-
class DbalSessionStorage extends NativeSessionStorage
18+
class DbalSessionStorage extends AbstractSessionStorage implements SessionSaveHandlerInterface
1619
{
20+
/**
21+
* @var Connection
22+
*/
1723
private $con;
24+
25+
/**
26+
* @var string
27+
*/
1828
private $tableName;
1929

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)
2139
{
22-
parent::__construct($options);
23-
2440
$this->con = $con;
2541
$this->tableName = $tableName;
26-
}
27-
28-
/**
29-
* Starts the session.
30-
*/
31-
public function start()
32-
{
33-
if (self::$sessionStarted) {
34-
return;
35-
}
3642

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);
4844
}
4945

5046
/**
@@ -102,7 +98,7 @@ public function sessionDestroy($id)
10298
*
10399
* @throws \RuntimeException If any old sessions cannot be cleaned
104100
*/
105-
public function sessionGC($lifetime)
101+
public function sessionGc($lifetime)
106102
{
107103
try {
108104
$this->con->executeQuery("DELETE FROM {$this->tableName} WHERE sess_time < :time", array(
@@ -140,7 +136,7 @@ public function sessionRead($id)
140136

141137
return '';
142138
} 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);
144140
}
145141
}
146142

@@ -181,7 +177,7 @@ public function sessionWrite($id, $data)
181177
$this->createNewSession($id, $data);
182178
}
183179
} 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);
185181
}
186182

187183
return true;

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ framework:
1010
default_locale: en
1111
session:
1212
auto_start: true
13-
storage_id: session.storage.filesystem
13+
storage_id: session.storage.mock_file
1414

1515
services:
1616
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }

src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpKernel\HttpKernelInterface;
1616
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1717
use Symfony\Bundle\TwigBundle\TwigEngine;
18+
use Symfony\Component\HttpFoundation\AutoExpireFlashBag;
1819

1920
/**
2021
* WebDebugToolbarListener injects the Web Debug Toolbar.
@@ -70,9 +71,12 @@ public function onKernelResponse(FilterResponseEvent $event)
7071
}
7172

7273
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
73-
if (null !== $session = $request->getSession()) {
74-
// keep current flashes for one more request
75-
$session->setFlashes($session->getFlashes());
74+
$session = $request->getSession();
75+
if ($session instanceof AutoExpireFlashBag) {
76+
// keep current flashes for one more request if using AutoExpireFlashBag
77+
foreach ($session->getFlashKeys() as $type) {
78+
$session->setFlashes($session->getFlashes($type));
79+
}
7680
}
7781

7882
$response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location'))));

0 commit comments

Comments
 (0)