diff --git a/Dotenv.php b/Dotenv.php index ba56003..6c30803 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -71,7 +71,7 @@ public function setProdEnvs(array $prodEnvs): self * * @return $this */ - public function usePutenv($usePutenv = true): self + public function usePutenv(bool $usePutenv = true): self { $this->usePutenv = $usePutenv; @@ -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; @@ -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; } @@ -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; } } @@ -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; } @@ -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]; diff --git a/composer.json b/composer.json index de8ec15..6e85c9f 100644 --- a/composer.json +++ b/composer.json @@ -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"