bug #29131 [Dotenv] dont use getenv() to read SYMFONY_DOTENV_VARS (nicolas-grekas)
This PR was merged into the 3.4 branch.
Discussion
----------
[Dotenv] dont use getenv() to read SYMFONY_DOTENV_VARS
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Since using it is not thread safe, let's not rely on it (already done in other places.)
Commits
-------
21a909a189
[Dotenv] dont use getenv() to read SYMFONY_DOTENV_VARS
This commit is contained in:
commit
d74a4eb2fa
@ -66,8 +66,8 @@ final class Dotenv
|
|||||||
*/
|
*/
|
||||||
public function populate($values)
|
public function populate($values)
|
||||||
{
|
{
|
||||||
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
|
$updateLoadedVars = false;
|
||||||
unset($loadedVars['']);
|
$loadedVars = array_flip(explode(',', isset($_SERVER['SYMFONY_DOTENV_VARS']) ? $_SERVER['SYMFONY_DOTENV_VARS'] : (isset($_ENV['SYMFONY_DOTENV_VARS']) ? $_ENV['SYMFONY_DOTENV_VARS'] : '')));
|
||||||
|
|
||||||
foreach ($values as $name => $value) {
|
foreach ($values as $name => $value) {
|
||||||
$notHttpName = 0 !== strpos($name, 'HTTP_');
|
$notHttpName = 0 !== strpos($name, 'HTTP_');
|
||||||
@ -82,14 +82,15 @@ final class Dotenv
|
|||||||
$_SERVER[$name] = $value;
|
$_SERVER[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loadedVars[$name] = true;
|
if (!isset($loadedVars[$name])) {
|
||||||
|
$loadedVars[$name] = $updateLoadedVars = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($loadedVars) {
|
if ($updateLoadedVars) {
|
||||||
|
unset($loadedVars['']);
|
||||||
$loadedVars = implode(',', array_keys($loadedVars));
|
$loadedVars = implode(',', array_keys($loadedVars));
|
||||||
putenv("SYMFONY_DOTENV_VARS=$loadedVars");
|
putenv('SYMFONY_DOTENV_VARS='.$_ENV['SYMFONY_DOTENV_VARS'] = $_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars);
|
||||||
$_ENV['SYMFONY_DOTENV_VARS'] = $loadedVars;
|
|
||||||
$_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ class DotenvTest extends TestCase
|
|||||||
|
|
||||||
public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar()
|
public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar()
|
||||||
{
|
{
|
||||||
putenv('SYMFONY_DOTENV_VARS=FOO,BAR,BAZ');
|
putenv('SYMFONY_DOTENV_VARS='.$_SERVER['SYMFONY_DOTENV_VARS'] = 'FOO,BAR,BAZ');
|
||||||
|
|
||||||
putenv('FOO=foo');
|
putenv('FOO=foo');
|
||||||
putenv('BAR=bar');
|
putenv('BAR=bar');
|
||||||
|
Reference in New Issue
Block a user