Skip to content

Commit 51791c2

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 744c099 commit 51791c2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Dotenv.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function populate(array $values, bool $overrideExistingVars = false): voi
135135
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));
136136

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

373373
private function resolveCommands(string $value, array $loadedVars): string
374374
{
375-
if (false === strpos($value, '$')) {
375+
if (!str_contains($value, '$')) {
376376
return $value;
377377
}
378378

@@ -408,7 +408,7 @@ private function resolveCommands(string $value, array $loadedVars): string
408408

409409
$env = [];
410410
foreach ($this->values as $name => $value) {
411-
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')))) {
411+
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')))) {
412412
$env[$name] = $value;
413413
}
414414
}
@@ -426,7 +426,7 @@ private function resolveCommands(string $value, array $loadedVars): string
426426

427427
private function resolveVariables(string $value, array $loadedVars): string
428428
{
429-
if (false === strpos($value, '$')) {
429+
if (!str_contains($value, '$')) {
430430
return $value;
431431
}
432432

@@ -461,7 +461,7 @@ private function resolveVariables(string $value, array $loadedVars): string
461461
$value = $this->values[$name];
462462
} elseif (isset($_ENV[$name])) {
463463
$value = $_ENV[$name];
464-
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
464+
} elseif (isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')) {
465465
$value = $_SERVER[$name];
466466
} elseif (isset($this->values[$name])) {
467467
$value = $this->values[$name];

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.1.3"
19+
"php": ">=7.1.3",
20+
"symfony/polyfill-php80": "^1.16"
2021
},
2122
"require-dev": {
2223
"symfony/process": "^3.4.2|^4.0|^5.0"

0 commit comments

Comments
 (0)