Skip to content

Instantly share code, notes, and snippets.

@cristobal
Created April 20, 2015 12:20
Show Gist options
  • Save cristobal/ffaad78677e7c9b1027b to your computer and use it in GitHub Desktop.
Save cristobal/ffaad78677e7c9b1027b to your computer and use it in GitHub Desktop.
Silex - Propel + Session in DB
<?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