Handle master/slave connections

This commit is contained in:
Kévin Gomez 2013-10-31 21:46:54 +00:00
parent e3fb952229
commit b96a828af1
2 changed files with 13 additions and 2 deletions

View file

@ -52,6 +52,7 @@ class PropelExtension extends Extension
}
// build properties
// @todo: store them as container parameters and use them in commands
if (isset($config['build_properties']) && is_array($config['build_properties'])) {
$buildProperties = $config['build_properties'];
} else {

View file

@ -12,6 +12,7 @@ namespace Propel\PropelBundle;
use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle;
use Propel\Runtime\Connection\ConnectionManagerMasterSlave;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -47,8 +48,17 @@ class PropelBundle extends Bundle
$serviceContainer->setDefaultDatasource($default_datasource);
foreach ($connections_config as $name => $config) {
$manager = new ConnectionManagerSingle();
$manager->setConfiguration($config['connection']);
if (isset($config['slaves'])) {
$manager = new ConnectionManagerMasterSlave();
// configure the master (write) connection
$manager->setWriteConfiguration($config['connection']);
// configure the slave (read) connections
$manager->setReadConfiguration($config['slaves']);
} else {
$manager = new ConnectionManagerSingle();
$manager->setConfiguration($config['connection']);
}
$serviceContainer->setAdapterClass($name, $config['adapter']);
$serviceContainer->setConnectionManager($name, $manager);