8000 bug #25163 [DI] Fix tracking of env vars in exceptions (nicolas-grekas) · symfony/symfony@8555c0b · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8555c0b

Browse files
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
2 parents ca5b15a + 73f1ac5 commit 8555c0b

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,26 @@ public function process(ContainerBuilder $container)
5252
}
5353
$config = $resolvingBag->resolveValue($config);
5454

55-
$tmpContainer = new ContainerBuilder($resolvingBag);
56-
$tmpContainer->setResourceTracking($container->isTrackingResources());
57-
$tmpContainer->addObjectResource($extension);
58-
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
59-
$tmpContainer->addObjectResource($configuration);
60-
}
55+
try {
56+
$tmpContainer = new ContainerBuilder($resolvingBag);
57+
$tmpContainer->setResourceTracking($container->isTrackingResources());
58+
$tmpContainer->addObjectResource($extension);
59+
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
60+
$tmpContainer->addObjectResource($configuration);
61+
}
6162

62-
foreach ($exprLangProviders as $provider) {
63-
$tmpContainer->addExpressionLanguageProvider($provider);
64-
}
63+
foreach ($exprLangProviders as $provider) {
64+
$tmpContainer->addExpressionLanguageProvider($provider);
65+
}
6566

66-
$extension->load($config, $tmpContainer);
67+
$extension->load($config, $tmpContainer);
68+
} catch (\Exception $e) {
69+
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
70+
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
71+
}
72+
73+
throw $e;
74+
}
6775

6876
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
6977
// don't keep track of env vars that are *overridden* when configs are merged

src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ public function testOverriddenEnvsAreMerged()
8484
$this->assertSame(array('BAZ', 'FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
8585
$this->assertSame(array('BAZ' => 1, 'FOO' => 0), $container->getEnvCounters());
8686
}
87+
88+
public function testThrowingExtensionsGetMergedBag()
89+
{
90+
$container = new ContainerBuilder();
91+
$container->registerExtension(new ThrowingExtension());
92+
$container->prependExtensionConfig('throwing', array('bar' => '%env(FOO)%'));
93+
94+
try {
95+
$pass = new MergeExtensionConfigurationPass();
96+
$pass->process($container);
97+
$this->fail('An exception should have been thrown.');
98+
} catch (\Exception $e) {
99+
}
100+
101+
$this->assertSame(array('FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
102+
}
87103
}
88104

89105
class FooConfiguration implements ConfigurationInterface
@@ -125,3 +141,21 @@ public function load(array $configs, ContainerBuilder $container)
125141
}
126142
}
127143
}
144+
145+
class ThrowingExtension extends Extension
146+
{
147+
public function getAlias()
148+
{
149+
return 'throwing';
150+
}
151+
152+
public function getConfiguration(array $config, ContainerBuilder $container)
153+
{
154+
return new FooConfiguration();
155+
}
156+
157+
public function load(array $configs, ContainerBuilder $container)
158+
{
159+
throw new \Exception();
160+
}
161+
}

0 commit comments

Comments
 (0)
0