[DI] Default undefined env to empty string during compile

This commit is contained in:
Roland Franssen 2018-10-12 16:41:04 +02:00 committed by Fabien Potencier
parent 61cf143727
commit 38a8ab92fa
2 changed files with 10 additions and 1 deletions

View File

@ -48,7 +48,7 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
$values = array();
if (false === $i = strpos($env, ':')) {
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : null;
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
$defaultType = null !== $default ? self::getType($default) : 'string';
$values[$defaultType] = $default;
} else {

View File

@ -48,6 +48,7 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
$container->registerExtension($ext = new EnvExtension());
$container->prependExtensionConfig('env_extension', $expected = array(
'float_node' => '%env(FLOATISH)%',
'string_node' => '%env(UNDEFINED)%',
));
$this->doProcess($container);
@ -311,6 +312,14 @@ class EnvConfiguration implements ConfigurationInterface
->arrayNode('simple_array_node')->end()
->enumNode('enum_node')->values(array('a', 'b'))->end()
->variableNode('variable_node')->end()
->scalarNode('string_node')
->validate()
->ifTrue(function ($value) {
return !\is_string($value);
})
->thenInvalid('%s is not a string')
->end()
->end()
->end();
return $treeBuilder;