Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  Leverage str_contains/str_starts_with
  Leverage str_ends_with
  • Loading branch information
nicolas-grekas committed Jul 21, 2021
2 parents 99a18c2 + 51791c2 commit f0fcb34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function populate(array $values, bool $overrideExistingVars = false): voi
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));

foreach ($values as $name => $value) {
$notHttpName = 0 !== strpos($name, 'HTTP_');
$notHttpName = !str_starts_with($name, 'HTTP_');
// don't check existence with getenv() because of thread safety issues
if (!isset($loadedVars[$name]) && (!$overrideExistingVars && (isset($_ENV[$name]) || (isset($_SERVER[$name]) && $notHttpName)))) {
continue;
Expand Down Expand Up @@ -427,7 +427,7 @@ private function skipEmptyLines()

private function resolveCommands(string $value, array $loadedVars): string
{
if (false === strpos($value, '$')) {
if (!str_contains($value, '$')) {
return $value;
}

Expand Down Expand Up @@ -463,7 +463,7 @@ private function resolveCommands(string $value, array $loadedVars): string

$env = [];
foreach ($this->values as $name => $value) {
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')))) {
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')))) {
$env[$name] = $value;
}
}
Expand All @@ -481,7 +481,7 @@ private function resolveCommands(string $value, array $loadedVars): string

private function resolveVariables(string $value, array $loadedVars): string
{
if (false === strpos($value, '$')) {
if (!str_contains($value, '$')) {
return $value;
}

Expand Down Expand Up @@ -516,7 +516,7 @@ private function resolveVariables(string $value, array $loadedVars): string
$value = $this->values[$name];
} elseif (isset($_ENV[$name])) {
$value = $_ENV[$name];
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
} elseif (isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')) {
$value = $_SERVER[$name];
} elseif (isset($this->values[$name])) {
$value = $this->values[$name];
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"require": {
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1"
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"symfony/process": "^4.4|^5.0"
Expand Down

0 comments on commit f0fcb34

Please sign in to comment.