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

This commit is contained in:
Christophe Coevoet 2011-06-17 09:59:01 +02:00
parent 627a7f7cd4
commit 41347bc3f5
3 changed files with 20 additions and 3 deletions

View File

@ -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()

View File

@ -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()
;

View File

@ -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',