Created
April 20, 2015 12:20
-
-
Save cristobal/ffaad78677e7c9b1027b to your computer and use it in GitHub Desktop.
Silex - Propel + Session in DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; | |
use Propel\Runtime\Propel; | |
use Propel\Runtime\Connection\ConnectionWrapper; | |
use Propel\Runtime\Connection\PdoConnection; | |
use Propel\Silex\PropelServiceProvider; | |
//-------------------------------------- | |
// Propel + Session in DB. | |
// @see | |
// - http://silex.sensiolabs.org/doc/cookbook/session_storage.html | |
//-------------------------------------- | |
$app->register(new PropelServiceProvider(),[ | |
'propel.config_file' => __DIR__ . '/config/propel.php' | |
]); | |
$app->register(new SessionServiceProvider()); | |
$app['session.storage.handler'] = $app->share(function () { | |
$name = Propel::getDefaultDatasource(); | |
$configuration = | |
Propel::getServiceContainer() | |
->getConnectionManager($name) | |
->getConfiguration(); | |
$pdo = new PdoConnection($configuration['dsn'], $configuration['user'], | |
$configuration['password']); | |
$con = new ConnectionWrapper($pdo); | |
return new PdoSessionHandler($con->getWrappedConnection()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment