Selaa lähdekoodia

[DoctrineBundle] updated to only load default settings once

Fixed a bug that caused DoctrineBundle to load default settings for
every parsed config file rather than just the first.  This caused
imported files to be override by default values.
Brandon Turner 15 vuotta sitten
vanhempi
commit
a3fc1be13f

+ 4 - 2
src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php

@@ -217,8 +217,10 @@ class DoctrineExtension extends Extension
      */
     protected function loadOrmDefaults(array $config, ContainerBuilder $container)
     {
-        $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
-        $loader->load($this->resources['orm']);
+        if (!$container->hasDefinition('doctrine.orm.metadata_driver.annotation')) {
+            $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
+            $loader->load($this->resources['orm']);
+        }
 
         // Allow these application configuration options to override the defaults
         $options = array(

+ 15 - 1
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

@@ -427,6 +427,20 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
         $this->assertEquals(11211, $calls[0][1][1]);
     }
 
+    public function testDependencyInjectionImportsOverrideDefaults()
+    {
+        $container = new ContainerBuilder();
+        $loader = $this->getDoctrineExtensionLoader();
+        $container->registerExtension($loader);
+
+        $this->loadFromFile($container, 'orm_imports');
+
+        $container->freeze();
+
+        $this->assertEquals('apc', $container->getParameter('doctrine.orm.metadata_cache_driver'));
+        $this->assertTrue($container->getParameter('doctrine.orm.auto_generate_proxy_classes'));
+    }
+
     protected function getDoctrineExtensionLoader($bundle = 'YamlBundle')
     {
         require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php';
@@ -434,4 +448,4 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
         $bundles = array('Fixtures\\Bundles\\'.$bundle.'\\'.$bundle);
         return new DoctrineExtension($bundleDirs, $bundles, sys_get_temp_dir());
     }
-}
+}

+ 18 - 0
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://www.symfony-project.org/schema/dic/services"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine"
+    xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
+                        http://www.symfony-project.org/schema/dic/doctrine/orm http://www.symfony-project.org/schema/dic/doctrine/orm/doctrine-1.0.xsd
+                        http://www.symfony-project.org/schema/dic/doctrine/dbal http://www.symfony-project.org/schema/dic/doctrine/dbal/doctrine-1.0.xsd">
+
+    <imports>
+        <import resource="orm_imports_import.xml" />
+    </imports>
+
+    <doctrine:orm
+        auto_generate_proxy_classes="true"
+    >
+    </doctrine:orm>
+</container>

+ 15 - 0
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://www.symfony-project.org/schema/dic/services"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine"
+    xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
+                        http://www.symfony-project.org/schema/dic/doctrine/orm http://www.symfony-project.org/schema/dic/doctrine/orm/doctrine-1.0.xsd
+                        http://www.symfony-project.org/schema/dic/doctrine/dbal http://www.symfony-project.org/schema/dic/doctrine/dbal/doctrine-1.0.xsd">
+
+    <doctrine:orm
+        auto_generate_proxy_classes="false"
+        metadata_cache_driver="apc"
+    >
+    </doctrine:orm>
+</container>

+ 6 - 0
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_imports.yml

@@ -0,0 +1,6 @@
+
+imports:
+  - { resource: orm_imports_import.yml }
+
+doctrine.orm:
+  auto_generate_proxy_classes: true

+ 4 - 0
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_imports_import.yml

@@ -0,0 +1,4 @@
+
+doctrine.orm:
+  auto_generate_proxy_classes: false
+  metadata_cache_driver: apc