[DoctrineBundle] fixed some configuration options

This commit is contained in:
Fabien Potencier 2011-05-04 11:35:14 +02:00
parent 736948887d
commit 0331501580
2 changed files with 31 additions and 20 deletions

View File

@ -74,8 +74,8 @@ class Configuration implements ConfigurationInterface
'path',
'memory',
'unix_socket',
'wrapper_class', 'wrapper-class', 'wrapperClass',
'platform_service', 'platform-service', 'platform-service',
'wrapper_class',
'platform_service',
'charset',
'logging'
) as $key) {
@ -128,22 +128,13 @@ class Configuration implements ConfigurationInterface
->scalarNode('platform_service')->end()
->scalarNode('charset')->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->end()
->fixXmlConfig('driver_class', 'driverClass')
->children()
->scalarNode('driverClass')->end()
->end()
->fixXmlConfig('options', 'driverOptions')
->children()
->arrayNode('driverOptions')
->scalarNode('driver_class')->end()
->scalarNode('wrapper_class')->end()
->arrayNode('options')
->useAttributeAsKey('key')
->prototype('scalar')->end()
->end()
->end()
->fixXmlConfig('wrapper_class', 'wrapperClass')
->children()
->scalarNode('wrapperClass')->end()
->end()
->end()
;

View File

@ -105,7 +105,7 @@ class DoctrineExtension extends AbstractDoctrineExtension
// connection
if (isset($connection['charset'])) {
if ((isset($connection['driver']) && stripos($connection['driver'], 'mysql') !== false) ||
(isset($connection['driverClass']) && stripos($connection['driverClass'], 'mysql') !== false)) {
(isset($connection['driver_class']) && stripos($connection['driver_class'], 'mysql') !== false)) {
$mysqlSessionInit = new Definition('%doctrine.dbal.events.mysql_session_init.class%');
$mysqlSessionInit->setArguments(array($connection['charset']));
$mysqlSessionInit->setPublic(false);
@ -119,21 +119,41 @@ class DoctrineExtension extends AbstractDoctrineExtension
}
}
if (isset($connection['platform_service'])) {
$connection['platform'] = new Reference($connection['platform_service']);
unset($connection['platform_service']);
}
$options = $this->getConnectionOptions($connection);
$container
->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new DefinitionDecorator('doctrine.dbal.connection'))
->setArguments(array(
$connection,
$options,
new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)),
new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)),
))
;
}
protected function getConnectionOptions($connection)
{
$options = $connection;
if (isset($options['platform_service'])) {
$options['platform'] = new Reference($options['platform_service']);
unset($options['platform_service']);
}
foreach (array(
'options' => 'driverOptions',
'driver_class' => 'driverClass',
'wrapper_class' => 'wrapperClass',
) as $old => $new) {
if (isset($options[$old])) {
$options[$new] = $options[$old];
unset($options[$old]);
}
}
return $options;
}
/**
* Loads the Doctrine ORM configuration.
*