Kaynağa Gözat

updated the framework to take into account the last changes of the DI component

Fabien Potencier 15 yıl önce
ebeveyn
işleme
dcaf436d9a

+ 2 - 7
src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/xml/Kernel.php

@@ -3,8 +3,7 @@
 require_once __DIR__.'/../src/autoload.php';
 
 use Symfony\Framework\Kernel;
-use Symfony\Components\DependencyInjection\Loader\XmlFileLoader as ContainerLoader;
-use Symfony\Components\DependencyInjection\ContainerBuilder;
+use Symfony\Components\DependencyInjection\Loader\LoaderInterface;
 
 use Symfony\Framework\Bundle\KernelBundle;
 use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
@@ -48,12 +47,8 @@ class {{ class }}Kernel extends Kernel
         );
     }
 
-    public function registerContainerConfiguration()
+    public function registerContainerConfiguration(LoaderInterface $loader)
     {
-        $container = new ContainerBuilder();
-        $loader = new ContainerLoader($container, $this->getBundleDirs());
         $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.xml');
-
-        return $container;
     }
 }

+ 2 - 7
src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/yaml/Kernel.php

@@ -3,8 +3,7 @@
 require_once __DIR__.'/../src/autoload.php';
 
 use Symfony\Framework\Kernel;
-use Symfony\Components\DependencyInjection\Loader\YamlFileLoader as ContainerLoader;
-use Symfony\Components\DependencyInjection\ContainerBuilder;
+use Symfony\Components\DependencyInjection\Loader\LoaderInterface;
 
 use Symfony\Framework\Bundle\KernelBundle;
 use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
@@ -48,12 +47,8 @@ class {{ class }}Kernel extends Kernel
         );
     }
 
-    public function registerContainerConfiguration()
+    public function registerContainerConfiguration(LoaderInterface $loader)
     {
-        $container = new ContainerBuilder();
-        $loader = new ContainerLoader($container, $this->getBundleDirs());
         $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
-
-        return $container;
     }
 }

+ 24 - 2
src/Symfony/Framework/Kernel.php

@@ -7,6 +7,13 @@ use Symfony\Components\DependencyInjection\ContainerBuilder;
 use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
 use Symfony\Components\DependencyInjection\Resource\FileResource;
 use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
+use Symfony\Components\DependencyInjection\Loader\DelegatingLoader;
+use Symfony\Components\DependencyInjection\Loader\LoaderResolver;
+use Symfony\Components\DependencyInjection\Loader\LoaderInterface;
+use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Components\DependencyInjection\Loader\YamlFileLoader;
+use Symfony\Components\DependencyInjection\Loader\IniFileLoader;
+use Symfony\Components\DependencyInjection\Loader\PhpFileLoader;
 use Symfony\Components\HttpFoundation\Request;
 use Symfony\Components\HttpKernel\HttpKernelInterface;
 
@@ -83,7 +90,7 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
 
     abstract public function registerBundleDirs();
 
-    abstract public function registerContainerConfiguration();
+    abstract public function registerContainerConfiguration(LoaderInterface $loader);
 
     /**
      * Checks whether the current kernel has been booted or not.
@@ -347,7 +354,10 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
                 $container->addObjectResource($bundle);
             }
         }
-        $container->merge($this->registerContainerConfiguration());
+
+        if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
+            $container->merge($cont);
+        }
         $container->freeze();
 
         foreach (array('cache', 'logs') as $name) {
@@ -377,6 +387,18 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
         }
     }
 
+    protected function getContainerLoader(ContainerInterface $container)
+    {
+        $resolver = new LoaderResolver(array(
+            new XmlFileLoader($container, $this->getBundleDirs()),
+            new YamlFileLoader($container, $this->getBundleDirs()),
+            new IniFileLoader($container, $this->getBundleDirs()),
+            new PhpFileLoader($container, $this->getBundleDirs()),
+        ));
+
+        return new DelegatingLoader($resolver);
+    }
+
     static public function stripComments($source)
     {
         if (!function_exists('token_get_all')) {

+ 2 - 1
tests/Symfony/Tests/Framework/KernelTest.php

@@ -12,6 +12,7 @@
 namespace Symfony\Tests\Framework;
 
 use Symfony\Framework\Kernel;
+use Symfony\Components\DependencyInjection\Loader\LoaderInterface;
 
 class KernelTest extends \PHPUnit_Framework_TestCase
 {
@@ -44,7 +45,7 @@ class KernelForTest extends Kernel
     {
     }
 
-    public function registerContainerConfiguration()
+    public function registerContainerConfiguration(LoaderInterface $loader)
     {
     }