Skip to content

Commit d8c11a1

Browse files
authored
Merge pull request #281 from Kal74/master
[#280] Do not instantiate PDOSessionHandler at build time
2 parents 6f5d7f2 + fb16e5d commit d8c11a1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

DependencyInjection/CompilerPass/PingableDriverCompilerPass.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Gos\Bundle\WebSocketBundle\DependencyInjection\CompilerPass;
44

55
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6-
use Symfony\Component\DependencyInjection\Container;
76
use Symfony\Component\DependencyInjection\ContainerBuilder;
87
use Symfony\Component\DependencyInjection\Reference;
9-
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
108

119
class PingableDriverCompilerPass implements CompilerPassInterface
1210
{
@@ -23,9 +21,9 @@ public function process(ContainerBuilder $container)
2321
return;
2422
}
2523

26-
$sessionHandler = $container->get((string) $container->getAlias('gos_web_socket.session_handler'));
24+
$sessionHandlerDefinition = $container->getDefinition((string) $container->getAlias('gos_web_socket.session_handler'));
2725

28-
if (false === $sessionHandler instanceof PdoSessionHandler) {
26+
if (!\in_array(\SessionHandlerInterface::class, \class_implements($sessionHandlerDefinition->getClass()), true)) {
2927
return;
3028
}
3129

Resources/docs/SessionSetup.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ arguments:
3434
- '%database_password%'
3535
```
3636
37+
If you're using Doctrine & want to re-use the same connection:
38+
39+
```yml
40+
services:
41+
session.handler.pdo:
42+
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
43+
arguments:
44+
- !service { class: PDO, factory: 'database_connection:getWrappedConnection' }
45+
- {lock_mode: 0}
46+
````
3747

3848
[Create table in your DB](http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html#mysql)
3949

0 commit comments

Comments
 (0)