Skip to content

Commit 7ce0ebe

Browse files
bug symfony#45529 [DependencyInjection] Don't reset env placeholders during compilation (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Don't reset env placeholders during compilation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#36466 | License | MIT | Doc PR | - Resetting causes placeholders to be lost when the env-var-in-config is used by several bundles (from linked issue.) Commits ------- fac5418 [DependencyInjection] Don't reset env placeholders during compilation
2 parents d6ba84f + fac5418 commit 7ce0ebe

File tree

2 files changed

+27
-39
lines changed

2 files changed

+27
-39
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ public function process(ContainerBuilder $container)
7979
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
8080
}
8181

82-
if ($configAvailable) {
83-
BaseNode::resetPlaceholders();
84-
}
85-
8682
throw $e;
8783
}
8884

@@ -95,10 +91,6 @@ public function process(ContainerBuilder $container)
9591
$container->getParameterBag()->add($parameters);
9692
}
9793

98-
if ($configAvailable) {
99-
BaseNode::resetPlaceholders();
100-
}
101-
10294
$container->addDefinitions($definitions);
10395
$container->addAliases($aliases);
10496
}

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

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,41 @@ public function process(ContainerBuilder $container)
4848

4949
$defaultBag = new ParameterBag($resolvingBag->all());
5050
$envTypes = $resolvingBag->getProvidedTypes();
51-
try {
52-
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
53-
$values = [];
54-
if (false === $i = strpos($env, ':')) {
55-
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
56-
$defaultType = null !== $default ? self::getType($default) : 'string';
57-
$values[$defaultType] = $default;
58-
} else {
59-
$prefix = substr($env, 0, $i);
60-
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
61-
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
62-
}
63-
}
64-
foreach ($placeholders as $placeholder) {
65-
BaseNode::setPlaceholder($placeholder, $values);
51+
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
52+
$values = [];
53+
if (false === $i = strpos($env, ':')) {
54+
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
55+
$defaultType = null !== $default ? self::getType($default) : 'string';
56+
$values[$defaultType] = $default;
57+
} else {
58+
$prefix = substr($env, 0, $i);
59+
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
60+
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
6661
}
6762
}
63+
foreach ($placeholders as $placeholder) {
64+
BaseNode::setPlaceholder($placeholder, $values);
65+
}
66+
}
6867

69-
$processor = new Processor();
68+
$processor = new Processor();
7069

71-
foreach ($extensions as $name => $extension) {
72-
if (!$extension instanceof ConfigurationExtensionInterface || !$config = array_filter($container->getExtensionConfig($name))) {
73-
// this extension has no semantic configuration or was not called
74-
continue;
75-
}
70+
foreach ($extensions as $name => $extension) {
71+
if (!$extension instanceof ConfigurationExtensionInterface || !$config = array_filter($container->getExtensionConfig($name))) {
72+
// this extension has no semantic configuration or was not called
73+
continue;
74+
}
7675

77-
$config = $resolvingBag->resolveValue($config);
76+
$config = $resolvingBag->resolveValue($config);
7877

79-
if (null === $configuration = $extension->getConfiguration($config, $container)) {
80-
continue;
81-
}
78+
if (null === $configuration = $extension->getConfiguration($config, $container)) {
79+
continue;
80+
}
8281

83-
try {
84-
$this->extensionConfig[$name] = $processor->processConfiguration($configuration, $config);
85-
} catch (TreeWithoutRootNodeException $e) {
86-
}
82+
try {
83+
$this->extensionConfig[$name] = $processor->processConfiguration($configuration, $config);
84+
} catch (TreeWithoutRootNodeException $e) {
8785
}
88-
} finally {
89-
BaseNode::resetPlaceholders();
9086
}
9187

9288
$resolvingBag->clearUnusedEnvPlaceholders();

0 commit comments

Comments
 (0)