8000 bug #28838 [DI] Default undefined env to empty string during compile … · symfony/symfony@72ab16d · GitHub
[go: up one dir, main page]

Skip to content

Commit 72ab16d

Browse files
committed
bug #28838 [DI] Default undefined env to empty string during compile (ro0NL)
This PR was squashed before being merged into the 4.1 branch (closes #28838). Discussion ---------- [DI] Default undefined env to empty string during compile | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28827 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Instead of using `null` for undefined envs, use `""` instead. We already default the type to string, so actually providing a string value makes sense. During runtime it will always be string also. Commits ------- 38a8ab9 [DI] Default undefined env to empty string during compile
2 parents 01808ca + 38a8ab9 commit 72ab16d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function process(ContainerBuilder $container)
4848
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
4949
$values = array();
5050
if (false === $i = strpos($env, ':')) {
51-
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : null;
51+
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
5252
$defaultType = null !== $default ? self::getType($default) : 'string';
5353
$values[$defaultType] = $default;
5454
} else {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function testDefaultEnvWithoutPrefixIsValidatedInConfig()
4848
$container->registerExtension($ext = new EnvExtension());
4949
$container->prependExtensionConfig('env_extension', $expected = array(
5050
'float_node' => '%env(FLOATISH)%',
51+
'string_node' => '%env(UNDEFINED)%',
5152
));
5253

5354
$this->doProcess($container);
@@ -311,6 +312,14 @@ public function getConfigTreeBuilder()
311312
->arrayNode('simple_array_node')->end()
312313
->enumNode('enum_node')->values(array('a', 'b'))->end()
313314
->variableNode('variable_node')->end()
315+
->scalarNode('string_node')
316+
->validate()
317+
->ifTrue(function ($value) {
318+
return !\is_string($value);
319+
})
320+
->thenInvalid('%s is not a string')
321+
->end()
322+
->end()
314323
->end();
315324

316325
return $treeBuilder;

0 commit comments

Comments
 (0)
0