Browse Source

[DoctrineBundle] fixed auto-mapping

When auto_mapping is true, you can avoid a bundle to be
automatically mapped by setting the value to false:

    auto_mapping: true
    mappings:
        BlogBundle: false

With the above configuration, all bundles will be
auto-mapped, but the BlogBundle won't be.

Bundles that are defined in mappings won't be
managed by the auto-mapping feature:

    auto_mapping: true
    mappings:
        BlogBundle: xml
Fabien Potencier 14 years ago
parent
commit
8b8545895f

+ 2 - 2
src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php

@@ -42,7 +42,7 @@ abstract class AbstractDoctrineExtension extends Extension
      */
     protected function loadMappingInformation(array $objectManager, ContainerBuilder $container)
     {
-        if (!$objectManager['mappings'] && $objectManager['auto_mapping']) {
+        if ($objectManager['auto_mapping']) {
             // automatically register bundle mappings
             foreach (array_keys($container->getParameter('kernel.bundles')) as $bundle) {
                 if (!isset($objectManager['mappings'][$bundle])) {
@@ -52,7 +52,7 @@ abstract class AbstractDoctrineExtension extends Extension
         }
 
         foreach ($objectManager['mappings'] as $mappingName => $mappingConfig) {
-            if (false === $mappingConfig) {
+            if (null !== $mappingConfig && false === $mappingConfig['mapping']) {
                 continue;
             }
 

+ 5 - 3
src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php

@@ -224,11 +224,13 @@ class Configuration implements ConfigurationInterface
                         ->prototype('array')
                             ->beforeNormalization()
                                 ->ifString()
-                                ->then(function($v) { return array ('type' => $v); })
+                                ->then(function($v) { return array('type' => $v); })
                             ->end()
-                            ->treatNullLike(array ())
+                            ->treatNullLike(array())
+                            ->treatFalseLike(array('mapping' => false))
                             ->performNoDeepMerging()
                             ->children()
+                                ->scalarNode('mapping')->defaultValue(true)->end()
                                 ->scalarNode('type')->end()
                                 ->scalarNode('dir')->end()
                                 ->scalarNode('alias')->end()
@@ -272,7 +274,7 @@ class Configuration implements ConfigurationInterface
             ->addDefaultsIfNotSet()
             ->beforeNormalization()
                 ->ifString()
-                ->then(function($v) { return array ('type' => $v); })
+                ->then(function($v) { return array('type' => $v); })
             ->end()
             ->children()
                 ->scalarNode('type')->defaultValue('array')->isRequired()->end()