bug #25163 [DI] Fix tracking of env vars in exceptions (nicolas-grekas)
This PR was merged into the 3.3 branch.
Discussion
----------
[DI] Fix tracking of env vars in exceptions
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #24270, #24368
| License | MIT
| Doc PR | -
Fixes the bad exception message reported in the linked issue (regression introduced in v3.3.7).
Best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/25163/files?w=1).
Commits
-------
73f1ac5
[DI] Fix tracking of env vars in exceptions
This commit is contained in:
commit
8555c0b550
@ -52,18 +52,26 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
$config = $resolvingBag->resolveValue($config);
|
$config = $resolvingBag->resolveValue($config);
|
||||||
|
|
||||||
$tmpContainer = new ContainerBuilder($resolvingBag);
|
try {
|
||||||
$tmpContainer->setResourceTracking($container->isTrackingResources());
|
$tmpContainer = new ContainerBuilder($resolvingBag);
|
||||||
$tmpContainer->addObjectResource($extension);
|
$tmpContainer->setResourceTracking($container->isTrackingResources());
|
||||||
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
|
$tmpContainer->addObjectResource($extension);
|
||||||
$tmpContainer->addObjectResource($configuration);
|
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
|
||||||
}
|
$tmpContainer->addObjectResource($configuration);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($exprLangProviders as $provider) {
|
foreach ($exprLangProviders as $provider) {
|
||||||
$tmpContainer->addExpressionLanguageProvider($provider);
|
$tmpContainer->addExpressionLanguageProvider($provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
$extension->load($config, $tmpContainer);
|
$extension->load($config, $tmpContainer);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
|
||||||
|
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
|
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
|
||||||
// don't keep track of env vars that are *overridden* when configs are merged
|
// 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', 'FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
|
||||||
$this->assertSame(array('BAZ' => 1, 'FOO' => 0), $container->getEnvCounters());
|
$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
|
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