Explorar el Código

Merge remote branch 'kriswallsmith/dic/lazy-compiler'

* kriswallsmith/dic/lazy-compiler:
  [DependencyInjection] made compiler lazy again since there are many temporary ContainerBuilder objects that don't use it
Fabien Potencier hace 14 años
padre
commit
031a65e4f8
Se han modificado 1 ficheros con 16 adiciones y 12 borrados
  1. 16 12
      src/Symfony/Component/DependencyInjection/ContainerBuilder.php

+ 16 - 12
src/Symfony/Component/DependencyInjection/ContainerBuilder.php

@@ -38,18 +38,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
     protected $injectors        = array();
     protected $compiler;
 
-    /**
-     * Constructor.
-     *
-     * @param ParameterBagInterface $parameterBag
-     */
-    public function __construct(ParameterBagInterface $parameterBag = null)
-    {
-        parent::__construct($parameterBag);
-
-        $this->compiler = new Compiler();
-    }
-
     /**
      * Registers an extension.
      *
@@ -175,6 +163,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
      */
     public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
     {
+        if (null === $this->compiler) {
+            $this->compiler = new Compiler();
+        }
+
         $this->compiler->addPass($pass, $type);
 
         $this->addObjectResource($pass);
@@ -187,6 +179,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
      */
     public function getCompilerPassConfig()
     {
+        if (null === $this->compiler) {
+            $this->compiler = new Compiler();
+        }
+
         return $this->compiler->getPassConfig();
     }
 
@@ -197,6 +193,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
      */
     public function getCompiler()
     {
+        if (null === $this->compiler) {
+            $this->compiler = new Compiler();
+        }
+
         return $this->compiler;
     }
 
@@ -391,6 +391,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
      */
     public function compile()
     {
+        if (null === $this->compiler) {
+            $this->compiler = new Compiler();
+        }
+
         foreach ($this->compiler->getPassConfig()->getPasses() as $pass) {
             $this->addObjectResource($pass);
         }