Permalink
Browse files

bug #29131 [Dotenv] dont use getenv() to read SYMFONY_DOTENV_VARS (ni…

…colas-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
-------

21a909a [Dotenv] dont use getenv() to read SYMFONY_DOTENV_VARS
  • Loading branch information...
nicolas-grekas committed Nov 8, 2018
2 parents a141ab0 + 21a909a commit d74a4eb2fa7bd06e21f22f0e687ad86415884cf8
Showing with 9 additions and 8 deletions.
  1. +8 −7 src/Symfony/Component/Dotenv/Dotenv.php
  2. +1 −1 src/Symfony/Component/Dotenv/Tests/DotenvTest.php
@@ -66,8 +66,8 @@ public function load($path/*, ...$paths*/)
*/
public function populate($values)
{
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
unset($loadedVars['']);
$updateLoadedVars = false;
$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) {
$notHttpName = 0 !== strpos($name, 'HTTP_');
@@ -82,14 +82,15 @@ public function populate($values)
$_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));
putenv("SYMFONY_DOTENV_VARS=$loadedVars");
$_ENV['SYMFONY_DOTENV_VARS'] = $loadedVars;
$_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars;
putenv('SYMFONY_DOTENV_VARS='.$_ENV['SYMFONY_DOTENV_VARS'] = $_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars);
}
}
@@ -268,7 +268,7 @@ public function testMemorizingLoadedVarsNamesInSpecialVar()
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('BAR=bar');

0 comments on commit d74a4eb

Please sign in to comment.