diff --git a/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php b/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php index 0460abefc6..e3b805a5ce 100644 --- a/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php +++ b/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php @@ -43,14 +43,23 @@ class ConnectionFactory * * @return Doctrine\DBAL\Connection */ - public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null) + public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array()) { if (!$this->initialized) { $this->initializeTypes(); $this->initialized = true; } - return DriverManager::getConnection($params, $config, $eventManager); + $connection = DriverManager::getConnection($params, $config, $eventManager); + + if (!empty($mappingTypes)) { + $platform = $connection->getDatabasePlatform(); + foreach ($mappingTypes as $dbType => $doctrineType) { + $platform->registerDoctrineTypeMapping($dbType, $doctrineType); + } + } + + return $connection; } private function initializeTypes() diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php index e221ef20a7..357a717ae5 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php @@ -77,7 +77,8 @@ class Configuration implements ConfigurationInterface 'wrapper_class', 'platform_service', 'charset', - 'logging' + 'logging', + 'mapping_types', ) as $key) { if (array_key_exists($key, $v)) { $connection[$key] = $v[$key]; @@ -115,6 +116,7 @@ class Configuration implements ConfigurationInterface ->requiresAtLeastOneElement() ->useAttributeAsKey('name') ->prototype('array') + ->fixXmlConfig('mapping_type') ->children() ->scalarNode('dbname')->end() ->scalarNode('host')->defaultValue('localhost')->end() @@ -134,6 +136,10 @@ class Configuration implements ConfigurationInterface ->useAttributeAsKey('key') ->prototype('scalar')->end() ->end() + ->arrayNode('mapping_types') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() ->end() ->end() ; diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php index 7c6d35a343..18fd7d3635 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -127,6 +127,7 @@ class DoctrineExtension extends AbstractDoctrineExtension $options, new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)), + $connection['mapping_types'], )) ; } @@ -139,6 +140,7 @@ class DoctrineExtension extends AbstractDoctrineExtension $options['platform'] = new Reference($options['platform_service']); unset($options['platform_service']); } + unset($options['mapping_types']); foreach (array( 'options' => 'driverOptions',