[DI] Auto register extension configuration classes as a resource
This commit is contained in:
parent
f1f5bff78f
commit
142416b7d4
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
|
||||
/**
|
||||
@ -47,6 +48,9 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface
|
||||
$tmpContainer = new ContainerBuilder($container->getParameterBag());
|
||||
$tmpContainer->setResourceTracking($container->isTrackingResources());
|
||||
$tmpContainer->addObjectResource($extension);
|
||||
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
|
||||
$tmpContainer->addObjectResource($configuration);
|
||||
}
|
||||
|
||||
foreach ($exprLangProviders as $provider) {
|
||||
$tmpContainer->addExpressionLanguageProvider($provider);
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
@ -48,4 +51,32 @@ class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(array($provider), $tmpProviders);
|
||||
}
|
||||
|
||||
public function testExtensionConfigurationIsTrackedByDefault()
|
||||
{
|
||||
$extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\Extension')->getMock();
|
||||
$extension->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->will($this->returnValue(new FooConfiguration()));
|
||||
$extension->expects($this->any())
|
||||
->method('getAlias')
|
||||
->will($this->returnValue('foo'));
|
||||
|
||||
$container = new ContainerBuilder(new ParameterBag());
|
||||
$container->registerExtension($extension);
|
||||
$container->prependExtensionConfig('foo', array('bar' => true));
|
||||
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertContains(new FileResource(__FILE__), $container->getResources(), '', false, false);
|
||||
}
|
||||
}
|
||||
|
||||
class FooConfiguration implements ConfigurationInterface
|
||||
{
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
return new TreeBuilder();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user