Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Backport slaves configuration #134

Merged
merged 4 commits into from

3 participants

@mrbase

back-ported the slaves configuration section to the 2.0 branch.

note i have removed the slaves section from the dbal level so you can only add slave connections to a master connection - this makes sense, global slaves, not so much.

@willdurand willdurand merged commit c032f46 into propelorm:2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
12 DependencyInjection/Configuration.php
@@ -169,6 +169,18 @@ private function getDbalConnectionsNode()
->scalarNode('password')->defaultValue('')->end()
->scalarNode('dsn')->defaultValue('')->end()
->scalarNode('classname')->defaultValue($this->debug ? 'DebugPDO' : 'PropelPDO')->end()
+ ->arrayNode('slaves')
+ ->useAttributeAsKey('name')
+ ->prototype('array')
+ ->children()
+ ->scalarNode('driver')->defaultValue('mysql')->end()
+ ->scalarNode('user')->defaultValue('root')->end()
+ ->scalarNode('password')->defaultValue('')->end()
+ ->scalarNode('dsn')->defaultValue('')->end()
+ ->scalarNode('classname')->defaultValue($this->debug ? 'DebugPDO' : 'PropelPDO')->end()
+ ->end()
+ ->end()
+ ->end()
->end()
->fixXmlConfig('option')
->children()
View
3  DependencyInjection/PropelExtension.php
@@ -104,6 +104,9 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$c = array();
foreach ($config['connections'] as $name => $conf) {
$c['datasources'][$name]['adapter'] = $conf['driver'];
+ if (!empty($conf['slaves'])) {
+ $c['datasources'][$name]['slaves']['connection'] = $conf['slaves'];
+ }
foreach (array('dsn', 'user', 'password', 'classname', 'options', 'attributes', 'settings') as $att) {
if (isset($conf[$att])) {
View
16 Resources/doc/README.markdown
@@ -90,11 +90,17 @@ propel:
attributes: {}
# default_connection: default
# connections:
-# default:
-# driver: mysql
-# user: root
-# password: null
-# dsn: mysql:host=localhost;dbname=test
+# default:
+# driver: mysql
+# user: root
+# password: null
+# dsn: mysql:host=localhost;dbname=test
+# slaves:
+# slave_server_1:
+# user: root
+# password: null
+# dsn: mysql:host=localhost;dbname=test_slave_1
+#
# options:
# ATTR_PERSISTENT: false
# attributes:
View
81 Tests/DependencyInjection/PropelExtensionTest.php
@@ -271,4 +271,85 @@ public function testDbalWithSettings()
$this->assertEquals('SET NAMES UTF8', $config['datasources']['default']['connection']['settings']['queries']['query']);
}
+ public function testDbalWithSlaves()
+ {
+ $container = $this->getContainer();
+ $loader = new PropelExtension();
+
+ $config_base = array(
+ 'path' => '/propel',
+ 'phing_path' => '/phing',
+ );
+
+ $config_mysql = array(
+ 'user' => 'mysql_usr',
+ 'password' => 'mysql_pwd',
+ 'dsn' => 'mysql_dsn',
+ 'driver' => 'mysql',
+ 'slaves' => array(
+ 'mysql_slave1' => array(
+ 'user' => 'mysql_usrs1',
+ 'password' => 'mysql_pwds1',
+ 'dsn' => 'mysql_dsns1',
+ ),
+ 'mysql_slave2' => array(
+ 'user' => 'mysql_usrs2',
+ 'password' => 'mysql_pwds2',
+ 'dsn' => 'mysql_dsns2',
+ ),
+ ),
+ );
+
+ $configs = array($config_base, array('dbal' => $config_mysql));
+ $loader->load($configs, $container);
+
+ $arguments = $container->getDefinition('propel.configuration')->getArguments();
+ $config = $arguments[0];
+
+ $this->assertArrayHasKey('slaves', $config['datasources']['default']);
+ $this->assertArrayHasKey('connection', $config['datasources']['default']['slaves']);
+ $this->assertArrayHasKey('mysql_slave1', $config['datasources']['default']['slaves']['connection']);
+ $this->assertArrayHasKey('user', $config['datasources']['default']['slaves']['connection']['mysql_slave1']);
+ $this->assertArrayHasKey('password', $config['datasources']['default']['slaves']['connection']['mysql_slave1']);
+ $this->assertArrayHasKey('dsn', $config['datasources']['default']['slaves']['connection']['mysql_slave1']);
+ $this->assertArrayHasKey('mysql_slave2', $config['datasources']['default']['slaves']['connection']);
+ $this->assertArrayHasKey('user', $config['datasources']['default']['slaves']['connection']['mysql_slave2']);
+ $this->assertArrayHasKey('password', $config['datasources']['default']['slaves']['connection']['mysql_slave2']);
+ $this->assertArrayHasKey('dsn', $config['datasources']['default']['slaves']['connection']['mysql_slave2']);
+
+ $this->assertEquals("mysql_usrs1", $config['datasources']['default']['slaves']['connection']['mysql_slave1']['user']);
+ $this->assertEquals("mysql_pwds1", $config['datasources']['default']['slaves']['connection']['mysql_slave1']['password']);
+ $this->assertEquals("mysql_dsns1", $config['datasources']['default']['slaves']['connection']['mysql_slave1']['dsn']);
+
+ $this->assertEquals("mysql_usrs2", $config['datasources']['default']['slaves']['connection']['mysql_slave2']['user']);
+ $this->assertEquals("mysql_pwds2", $config['datasources']['default']['slaves']['connection']['mysql_slave2']['password']);
+ $this->assertEquals("mysql_dsns2", $config['datasources']['default']['slaves']['connection']['mysql_slave2']['dsn']);
+ }
+
+ public function testDbalWithNoSlaves()
+ {
+ $container = $this->getContainer();
+ $loader = new PropelExtension();
+
+ $config_base = array(
+ 'path' => '/propel',
+ 'phing_path' => '/phing',
+ );
+
+ $config_mysql = array(
+ 'user' => 'mysql_usr',
+ 'password' => 'mysql_pwd',
+ 'dsn' => 'mysql_dsn',
+ 'driver' => 'mysql'
+ );
+
+ $configs = array($config_base, array('dbal' => $config_mysql));
+ $loader->load($configs, $container);
+
+ $arguments = $container->getDefinition('propel.configuration')->getArguments();
+ $config = $arguments[0];
+
+ $this->assertArrayNotHasKey('slaves', $config['datasources']['default']);
+ }
+
}
Something went wrong with that request. Please try again.