Переглянути джерело

[DependencyInjection] moved loading stack from static to object scope

Kris Wallsmith 14 роки тому
батько
коміт
8d6da86016

+ 5 - 6
src/Symfony/Component/DependencyInjection/Container.php

@@ -56,6 +56,7 @@ class Container implements ContainerInterface
 {
     protected $parameterBag;
     protected $services;
+    protected $loading = array();
 
     /**
      * Constructor.
@@ -183,24 +184,22 @@ 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;
         }

+ 1 - 1
tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php

@@ -109,7 +109,7 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
             @$builder->get('baz');
             $this->fail('->get() throws a LogicException if the service has a circular reference to itself');
         } catch (\LogicException $e) {
-            $this->assertEquals('The service "baz" has a circular reference to itself.', $e->getMessage(), '->get() throws a LogicException if the service has a circular reference to itself');
+            $this->assertEquals('Circular reference detected for service "baz" (services currently loading: baz).', $e->getMessage(), '->get() throws a LogicException if the service has a circular reference to itself');
         }
 
         $builder->register('foobar', 'stdClass')->setShared(true);