Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87a65d8

Browse files
bug#50530 [DependencyInjection] Fix support forfalse boolean env vars (Okhoshi)
This PR was merged into the 6.3 branch.Discussion----------[DependencyInjection] Fix support for `false` boolean env vars| Q | A| ------------- | ---| Branch? | 6.3| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -After upgrading `symfony/dependency-injection` package to version 6.3, some of our env vars couldn't be found anymore.For some scripts, we are providing an adhoc default value to env vars by setting `$_SERVER` directly. However, since version 6.3 of the DependencyInjection component, setting an env var to `false` (the boolean value, like in the snippet below) doesn't work anymore, and Symfony reports that the variable cannot be found.```php$_SERVER['FOO'] = false;```It seems to be a side effect of the changes made in#48705.Commits-------5101d18 [DependencyInjection] Fix support for `false` boolean env vars
2 parentsd9a8902 +5101d18 commit87a65d8

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

‎src/Symfony/Component/DependencyInjection/EnvVarProcessor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
146146
if (false !==$i ||'string' !==$prefix) {
147147
$env =$getEnv($name);
148148
}elseif ('' === ($env =$_ENV[$name] ?? (str_starts_with($name,'HTTP_') ?null : ($_SERVER[$name] ??null)))
149-
||false=== ($env =$env ??getenv($name) ??false)// null is a possible value because of thread safety issues
149+
||(false!==$env &&false === ($env =$env ??getenv($name) ??false))// null is a possible value because of thread safety issues
150150
) {
151151
foreach ($this->loadedVarsas$vars) {
152152
if (false !== ($env = ($vars[$name] ??$env)) &&'' !==$env) {

‎src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,67 @@ public static function validStrings()
5959
];
6060
}
6161

62+
/**
63+
* @dataProvider validRealEnvValues
64+
*/
65+
publicfunctiontestGetEnvRealEnv($value,$processed)
66+
{
67+
$_ENV['FOO'] =$value;
68+
69+
$processor =newEnvVarProcessor(newContainer());
70+
71+
$result =$processor->getEnv('string','FOO',function () {
72+
$this->fail('Should not be called');
73+
});
74+
75+
$this->assertSame($processed,$result);
76+
77+
unset($_ENV['FOO']);
78+
}
79+
80+
publicstaticfunctionvalidRealEnvValues()
81+
{
82+
return [
83+
['hello','hello'],
84+
[true,'1'],
85+
[false,''],
86+
[1,'1'],
87+
[0,'0'],
88+
[1.1,'1.1'],
89+
[10,'10'],
90+
];
91+
}
92+
93+
publicfunctiontestGetEnvRealEnvInvalid()
94+
{
95+
$_ENV['FOO'] =null;
96+
$this->expectException(EnvNotFoundException::class);
97+
$this->expectExceptionMessage('Environment variable not found: "FOO".');
98+
99+
$processor =newEnvVarProcessor(newContainer());
100+
101+
$processor->getEnv('string','FOO',function () {
102+
$this->fail('Should not be called');
103+
});
104+
105+
unset($_ENV['FOO']);
106+
}
107+
108+
publicfunctiontestGetEnvRealEnvNonScalar()
109+
{
110+
$_ENV['FOO'] = [];
111+
$this->expectException(RuntimeException::class);
112+
$this->expectExceptionMessage('Non-scalar env var "FOO" cannot be cast to "string".');
113+
114+
$processor =newEnvVarProcessor(newContainer());
115+
116+
$processor->getEnv('string','FOO',function () {
117+
$this->fail('Should not be called');
118+
});
119+
120+
unset($_ENV['FOO']);
121+
}
122+
62123
/**
63124
* @dataProvider validBools
64125
*/
@@ -97,6 +158,7 @@ public static function validBools()
97158
['true',true],
98159
['false',false],
99160
['null',false],
161+
['',false],
100162
['1',true],
101163
['0',false],
102164
['1.1',true],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp