Ver Fonte

[DoctrineBundle] Added the support of custom types for the platform

Christophe Coevoet há 14 anos atrás
pai
commit
41347bc3f5

+ 11 - 2
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()

+ 7 - 1
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()
         ;

+ 2 - 0
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',