Skip to content

Commit

Permalink
Added a configuration setting for commented types
Browse files Browse the repository at this point in the history
Types are commented by default as most of the custom types need it.
Types can only be marked as commented for all connections or none.
  • Loading branch information
stof committed Feb 12, 2012
1 parent 8382e6d commit 8ae66d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
15 changes: 11 additions & 4 deletions ConnectionFactory.php
Expand Up @@ -25,6 +25,7 @@
class ConnectionFactory
{
private $typesConfig = array();
private $commentedTypes = array();
private $initialized = false;

/**
Expand All @@ -44,7 +45,7 @@ public function __construct(array $typesConfig)
* @param Configuration $config
* @param EventManager $eventManager
*
* @return Doctrine\DBAL\Connection
* @return \Doctrine\DBAL\Connection
*/
public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
{
Expand All @@ -60,18 +61,24 @@ public function createConnection(array $params, Configuration $config = null, Ev
foreach ($mappingTypes as $dbType => $doctrineType) {
$platform->registerDoctrineTypeMapping($dbType, $doctrineType);
}
foreach ($this->commentedTypes as $type) {
$platform->markDoctrineTypeCommented(Type::getType($type));
}
}

return $connection;
}

private function initializeTypes()
{
foreach ($this->typesConfig as $type => $className) {
foreach ($this->typesConfig as $type => $typeConfig) {
if (Type::hasType($type)) {
Type::overrideType($type, $className);
Type::overrideType($type, $typeConfig['class']);
} else {
Type::addType($type, $className);
Type::addType($type, $typeConfig['class']);
}
if ($typeConfig['commented']) {
$this->commentedTypes[] = $type;
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion DependencyInjection/Configuration.php
Expand Up @@ -102,7 +102,16 @@ private function addDbalSection(ArrayNodeDefinition $node)
->children()
->arrayNode('types')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->prototype('array')
->beforeNormalization()
->ifString()
->then(function($v) { return array('class' => $v); })
->end()
->children()
->scalarNode('class')->isRequired()->end()
->booleanNode('commented')->defaultTrue()->end()
->end()
->end()
->end()
->end()
->fixXmlConfig('connection')
Expand Down
Expand Up @@ -654,7 +654,7 @@ public function testSetTypes()
$this->compileContainer($container);

$this->assertEquals(
array('test' => 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType'),
array('test' => array('class' => 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType', 'commented' => true)),
$container->getParameter('doctrine.dbal.connection_factory.types')
);
$this->assertEquals('%doctrine.dbal.connection_factory.types%', $container->getDefinition('doctrine.dbal.connection_factory')->getArgument(0));
Expand Down

0 comments on commit 8ae66d3

Please sign in to comment.