From de6c353b40176937209580c13c1f960187e8b1e6 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 8 Mar 2011 05:34:07 -0800 Subject: [PATCH] [DependencyInjection] made compiler lazy again since there are many temporary ContainerBuilder objects that don't use it --- .../DependencyInjection/ContainerBuilder.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index b89b7344ba..6ce1542aa6 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/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); }