Skip to content

Commit

Permalink
[DependencyInjection] extensions should only load if called during co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
kriswallsmith committed Mar 3, 2011
1 parent af59ee8 commit 0e12c55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
7 changes: 6 additions & 1 deletion Compiler/MergeExtensionConfigurationPass.php
Expand Up @@ -30,10 +30,15 @@ public function process(ContainerBuilder $container)
$aliases = $container->getAliases();

foreach ($container->getExtensions() as $name => $extension) {
if (!$config = $container->getExtensionConfig($name)) {
// this extension was not called
continue;
}

$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->addObjectResource($extension);

$extension->load($container->getExtensionConfig($name), $tmpContainer);
$extension->load($config, $tmpContainer);

$container->merge($tmpContainer);
}
Expand Down
47 changes: 12 additions & 35 deletions ContainerBuilder.php
Expand Up @@ -46,6 +46,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
public function __construct(ParameterBagInterface $parameterBag = null)
{
parent::__construct($parameterBag);

$this->compiler = new Compiler();
}

/**
Expand Down Expand Up @@ -166,47 +168,35 @@ public function loadFromExtension($extension, array $values = array())
}

/**
* Adds a compiler pass at the end of the current passes
* Adds a compiler pass.
*
* @param CompilerPassInterface $pass
* @param string $type
* @param CompilerPassInterface $pass A compiler pass
* @param string $type The type of compiler pass
*/
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
{
if (null === $this->compiler) {
$this->initializeCompiler();
}

$this->compiler->addPass($pass, $type);

$this->addObjectResource($pass);
}

/**
* Returns the compiler pass config which can then be modified
* Returns the compiler pass config which can then be modified.
*
* @return PassConfig
* @return PassConfig The compiler pass config
*/
public function getCompilerPassConfig()
{
if (null === $this->compiler) {
$this->initializeCompiler();
}

return $this->compiler->getPassConfig();
}

/**
* Returns the compiler instance
* Returns the compiler.
*
* @return Compiler
* @return Compiler The compiler
*/
public function getCompiler()
{
if (null === $this->compiler) {
$this->initializeCompiler();
}

return $this->compiler;
}

Expand Down Expand Up @@ -379,7 +369,7 @@ public function merge(ContainerBuilder $container)
public function getExtensionConfig($name)
{
if (!isset($this->extensionConfigs[$name])) {
return array(array());
$this->extensionConfigs[$name] = array();
}

return $this->extensionConfigs[$name];
Expand All @@ -401,8 +391,8 @@ public function getExtensionConfig($name)
*/
public function compile()
{
if (null === $this->compiler) {
$this->initializeCompiler();
foreach ($this->compiler->getPassConfig()->getPasses() as $pass) {
$this->addObjectResource($pass);
}

$this->compiler->compile($this);
Expand Down Expand Up @@ -836,19 +826,6 @@ public function findTaggedServiceIds($name)
return $tags;
}

/**
* Initializes the compiler
*
* @return void
*/
protected function initializeCompiler()
{
$this->compiler = new Compiler();
foreach ($this->compiler->getPassConfig()->getPasses() as $pass) {
$this->addObjectResource($pass);
}
}

/**
* Returns the Service Conditionals.
*
Expand Down

0 comments on commit 0e12c55

Please sign in to comment.