10000 [DI] Fix tracking of env vars in exceptions by nicolas-grekas · Pull Request #25163 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Fix tracking of env vars in exceptions #25163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,26 @@ public function process(ContainerBuilder $container)
}
$config = $resolvingBag->resolveValue($config);

$tmpContainer = new ContainerBuilder($resolvingBag);
$tmpContainer->setResourceTracking($container->isTrackingResources());
$tmpContainer->addObjectResource($extension);
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
$tmpContainer->addObjectResource($configuration);
}
try {
$tmpContainer = new ContainerBuilder($resolvingBag);
$tmpContainer->setResourceTracking($container->isTrackingResources());
$tmpContainer->addObjectResource($extension);
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment in condition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :) Was here before, and not forbidden by our policy, you can find many others in the code base.

$tmpContainer->addObjectResource($configuration);
}

foreach ($exprLangProviders as $provider) {
$tmpContainer->addExpressionLanguageProvider($provider);
}
foreach ($exprLangProviders as $provider) {
$tmpContainer->addExpressionLanguageProvider($provider);
}

$extension->load($config, $tmpContainer);
$extension->load($config, $tmpContainer);
} catch (\Exception $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to specify less general exception?

Copy link
Member Author
@nicolas-grekas nicolas-grekas Nov 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a bug. Could be "finally" in fact.

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ public function testOverriddenEnvsAreMerged()
$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
Expand Down Expand Up @@ -125,3 +141,21 @@ public function load(array $configs, ContainerBuilder $container)
}
}
}

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();
}
}
0