Skip to content

Commit

Permalink
[DoctrineBundle] added back the possibility to easily define one DBAL…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Apr 27, 2011
1 parent 7395069 commit e63c2e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Expand Up @@ -58,6 +58,22 @@ private function addDbalSection(ArrayNodeDefinition $node)
$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()
Expand Down
Expand Up @@ -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"
Expand Down
@@ -1,9 +1,6 @@
doctrine:
dbal:
default_connection: mysql
connections:
mysql:
dbname: mysql_db
user: mysql_user
password: mysql_s3cr3t
unix_socket: /path/to/mysqld.sock
dbname: mysql_db
user: mysql_user
password: mysql_s3cr3t
unix_socket: /path/to/mysqld.sock

1 comment on commit e63c2e2

@stfalcon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have problem with dbal encoding after your last changes

Please sign in to comment.