[DI] Fix tracking of env vars in exceptions
This commit is contained in:
parent
ca5b15a53b
commit
73f1ac5ea2
@ -52,6 +52,7 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface
|
||||
}
|
||||
$config = $resolvingBag->resolveValue($config);
|
||||
|
||||
try {
|
||||
$tmpContainer = new ContainerBuilder($resolvingBag);
|
||||
$tmpContainer->setResourceTracking($container->isTrackingResources());
|
||||
$tmpContainer->addObjectResource($extension);
|
||||
@ -64,6 +65,13 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
$extension->load($config, $tmpContainer);
|
||||
} catch (\Exception $e) {
|
||||
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
|
||||
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
|
||||
// don't keep track of env vars that are *overridden* when configs are merged
|
||||
|
@ -84,6 +84,22 @@ class MergeExtensionConfigurationPassTest extends TestCase
|
||||
$this->assertSame(array('BAZ', 'FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
|
||||
$this->assertSame(array('BAZ' => 1, 'FOO' => 0), $container->getEnvCounters());
|
||||
}
|
||||
|
||||
public function testThrowingExtensionsGetMergedBag()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new ThrowingExtension());
|
||||
$container->prependExtensionConfig('throwing', array('bar' => '%env(FOO)%'));
|
||||
|
||||
try {
|
||||
$pass = new MergeExtensionConfigurationPass();
|
||||
$pass->process($container);
|
||||
$this->fail('An exception should have been thrown.');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$this->assertSame(array('FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
|
||||
}
|
||||
}
|
||||
|
||||
class FooConfiguration implements ConfigurationInterface
|
||||
@ -125,3 +141,21 @@ class FooExtension extends Extension
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ThrowingExtension extends Extension
|
||||
{
|
||||
public function getAlias()
|
||||
{
|
||||
return 'throwing';
|
||||
}
|
||||
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new FooConfiguration();
|
||||
}
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user