[DI] Default undefined env to empty string during compile
This commit is contained in:
parent
61cf143727
commit
38a8ab92fa
@ -48,7 +48,7 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
|
|||||||
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
|
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
|
||||||
$values = array();
|
$values = array();
|
||||||
if (false === $i = strpos($env, ':')) {
|
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';
|
$defaultType = null !== $default ? self::getType($default) : 'string';
|
||||||
$values[$defaultType] = $default;
|
$values[$defaultType] = $default;
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,6 +48,7 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
|||||||
$container->registerExtension($ext = new EnvExtension());
|
$container->registerExtension($ext = new EnvExtension());
|
||||||
$container->prependExtensionConfig('env_extension', $expected = array(
|
$container->prependExtensionConfig('env_extension', $expected = array(
|
||||||
'float_node' => '%env(FLOATISH)%',
|
'float_node' => '%env(FLOATISH)%',
|
||||||
|
'string_node' => '%env(UNDEFINED)%',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->doProcess($container);
|
$this->doProcess($container);
|
||||||
@ -311,6 +312,14 @@ class EnvConfiguration implements ConfigurationInterface
|
|||||||
->arrayNode('simple_array_node')->end()
|
->arrayNode('simple_array_node')->end()
|
||||||
->enumNode('enum_node')->values(array('a', 'b'))->end()
|
->enumNode('enum_node')->values(array('a', 'b'))->end()
|
||||||
->variableNode('variable_node')->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();
|
->end();
|
||||||
|
|
||||||
return $treeBuilder;
|
return $treeBuilder;
|
||||||
|
Reference in New Issue
Block a user