Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a configuration setting for commented types

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...
commit 8ae66d37fc550633c67c1df09bca30947134adca 1 parent 8382e6d
@stof stof authored
View
15 ConnectionFactory.php
@@ -25,6 +25,7 @@
class ConnectionFactory
{
private $typesConfig = array();
+ private $commentedTypes = array();
private $initialized = false;
/**
@@ -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())
{
@@ -60,6 +61,9 @@ 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;
@@ -67,11 +71,14 @@ public function createConnection(array $params, Configuration $config = null, Ev
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;
}
}
}
View
11 DependencyInjection/Configuration.php
@@ -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')
View
2  Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.