[DoctrineBundle] added back the possibility to easily define one DBAL connection
The reasonning reads as follows: Most users will only ever use one database connection (and probably one entity manager for that matter). So, this most common use case should be as easy as possible to configure. This is BC. Before: doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql dbname: Symfony2 user: root password: null After (optional): doctrine: dbal: driver: pdo_mysql dbname: Symfony2 user: root password: null
This commit is contained in:
parent
7395069b60
commit
e63c2e2315
@ -58,6 +58,22 @@ class Configuration implements ConfigurationInterface
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('dbal')
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v) && !array_key_exists('connection', $v); })
|
||||
->then(function ($v) {
|
||||
$connection = array();
|
||||
foreach (array('dbname', 'host', 'port', 'user', 'password', 'driver', 'driver_class', 'options', 'path', 'memory', 'unix_socket', 'wrapper_class', 'platform_service', 'charset', 'logging') as $key) {
|
||||
if (array_key_exists($key, $v)) {
|
||||
$connection[$key] = $v[$key];
|
||||
unset($v[$key]);
|
||||
}
|
||||
}
|
||||
$v['default_connection'] = isset($v['default_connection']) ? (string) $v['default_connection'] : 'default';
|
||||
$v['connections'] = array($v['default_connection'] => $connection);
|
||||
|
||||
return $v;
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('default_connection')->end()
|
||||
->end()
|
||||
|
@ -7,7 +7,7 @@
|
||||
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
|
||||
|
||||
<config>
|
||||
<dbal default-connection="mysql">
|
||||
<dbal>
|
||||
<connection
|
||||
name="mysql"
|
||||
dbname="mysql_db"
|
||||
|
@ -1,8 +1,5 @@
|
||||
doctrine:
|
||||
dbal:
|
||||
default_connection: mysql
|
||||
connections:
|
||||
mysql:
|
||||
dbname: mysql_db
|
||||
user: mysql_user
|
||||
password: mysql_s3cr3t
|
||||
|
Reference in New Issue
Block a user