Skip to content

Commit 92b7ec9

Browse files
committed
Allow the env() default value to be null
1 parent 59f9949 commit 92b7ec9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function get($name)
4141
if ($this->has($name)) {
4242
$defaultValue = parent::get($name);
4343

44-
if (!is_scalar($defaultValue)) {
45-
throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar, but "%s" given to "%s".', gettype($defaultValue), $name));
44+
if (null !== $defaultValue && !is_scalar($defaultValue)) {
45+
throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', gettype($defaultValue), $name));
4646
}
4747
}
4848

src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,24 @@ public function testResolveThrowsOnBadDefaultValue()
139139
$bag->set('env(Array_Var)', array());
140140
$bag->resolve();
141141
}
142+
143+
public function testGetEndAllowsNull()
144+
{
145+
$bag = new EnvPlaceholderParameterBag();
146+
$bag->set('env(NULL_VAR)', null);
147+
$bag->get('env(NULL_VAR)');
148+
$bag->resolve();
149+
}
150+
151+
/**
152+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
153+
* @expectedExceptionMessage The default value of an env() parameter must be scalar or null, but "array" given to "env(ARRAY_VAR)".
154+
*/
155+
public function testGetThrowsOnBadDefaultValue()
156+
{
157+
$bag = new EnvPlaceholderParameterBag();
158+
$bag->set('env(ARRAY_VAR)', array());
159+
$bag->get('env(ARRAY_VAR)');
160+
$bag->resolve();
161+
}
142162
}

0 commit comments

Comments
 (0)