2015-08-17 17:00:26 -07:00
< ? php
/*
* This file is part of the Symfony package .
*
* ( c ) Fabien Potencier < fabien @ symfony . com >
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
namespace Symfony\Component\DependencyInjection\Compiler ;
use Symfony\Component\DependencyInjection\ContainerBuilder ;
2017-04-13 15:53:35 +01:00
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface ;
2015-08-17 17:00:26 -07:00
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface ;
/**
* Merges extension configs into the container builder .
*
* @ author Fabien Potencier < fabien @ symfony . com >
*/
class MergeExtensionConfigurationPass implements CompilerPassInterface
{
/**
* { @ inheritdoc }
*/
public function process ( ContainerBuilder $container )
{
$parameters = $container -> getParameterBag () -> all ();
$definitions = $container -> getDefinitions ();
$aliases = $container -> getAliases ();
$exprLangProviders = $container -> getExpressionLanguageProviders ();
foreach ( $container -> getExtensions () as $extension ) {
if ( $extension instanceof PrependExtensionInterface ) {
$extension -> prepend ( $container );
}
}
foreach ( $container -> getExtensions () as $name => $extension ) {
if ( ! $config = $container -> getExtensionConfig ( $name )) {
// this extension was not called
continue ;
}
$config = $container -> getParameterBag () -> resolveValue ( $config );
$tmpContainer = new ContainerBuilder ( $container -> getParameterBag ());
$tmpContainer -> setResourceTracking ( $container -> isTrackingResources ());
$tmpContainer -> addObjectResource ( $extension );
2017-04-13 15:53:35 +01:00
if ( $extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension -> getConfiguration ( $config , $tmpContainer )) {
$tmpContainer -> addObjectResource ( $configuration );
}
2015-08-17 17:00:26 -07:00
foreach ( $exprLangProviders as $provider ) {
$tmpContainer -> addExpressionLanguageProvider ( $provider );
}
$extension -> load ( $config , $tmpContainer );
$container -> merge ( $tmpContainer );
$container -> getParameterBag () -> add ( $parameters );
}
$container -> addDefinitions ( $definitions );
$container -> addAliases ( $aliases );
}
}