Bladeren bron

[HttpKernel] made a small tweak

Fabien Potencier 14 jaren geleden
bovenliggende
commit
67f13fee9e

+ 2 - 1
src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php

@@ -87,7 +87,8 @@ class Kernel extends BaseKernel
 
         $this->bundles = $this->registerBundles();
         $this->bundleDirs = $this->registerBundleDirs();
-        $this->container = $this->initializeContainer();
+
+        $this->initializeContainer();
 
         foreach ($this->bundles as $bundle) {
             $bundle->setContainer($this->container);

+ 4 - 5
src/Symfony/Component/HttpKernel/Kernel.php

@@ -142,7 +142,8 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
 
         $this->bundles = $this->registerBundles();
         $this->bundleDirs = $this->registerBundleDirs();
-        $this->container = $this->initializeContainer();
+
+        $this->initializeContainer();
 
         // load core classes
         ClassCollectionLoader::load(
@@ -343,10 +344,8 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
 
         require_once $location.'.php';
 
-        $container = new $class();
-        $container->set('kernel', $this);
-
-        return $container;
+        $this->container = new $class();
+        $this->container->set('kernel', $this);
     }
 
     public function getKernelParameters()

+ 5 - 5
src/Symfony/Component/HttpKernel/bootstrap.php

@@ -307,6 +307,7 @@ class Container implements ContainerInterface
 {
     protected $parameterBag;
     protected $services;
+    protected $loading = array();
     public function __construct(ParameterBagInterface $parameterBag = null)
     {
         $this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
@@ -349,18 +350,17 @@ class Container implements ContainerInterface
     }
     public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
     {
-        static $loading = array();
         $id = strtolower($id);
         if (isset($this->services[$id])) {
             return $this->services[$id];
         }
-        if (isset($loading[$id])) {
-            throw new \LogicException(sprintf('Circular reference detected for service "%s" (services currently loading: %s).', $id, implode(', ', array_keys($loading))));
+        if (isset($this->loading[$id])) {
+            throw new \LogicException(sprintf('Circular reference detected for service "%s" (services currently loading: %s).', $id, implode(', ', array_keys($this->loading))));
         }
         if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
-            $loading[$id] = true;
+            $this->loading[$id] = true;
             $service = $this->$method();
-            unset($loading[$id]);
+            unset($this->loading[$id]);
             return $service;
         }
         if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {