From 99a18c2e23f4d901c36cea2012f9f1a8e25e99e4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jul 2021 15:24:31 +0200 Subject: [PATCH 1/2] Backport type fixes --- Dotenv.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dotenv.php b/Dotenv.php index ba56003..ade7fa5 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; From 51791c28e2fb56ff5b508fd8d5d5e3c0514c6b7a Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 7 Jun 2021 01:15:42 +0200 Subject: [PATCH 2/2] Leverage str_contains/str_starts_with Signed-off-by: Alexander M. Turek --- Dotenv.php | 10 +++++----- composer.json | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Dotenv.php b/Dotenv.php index 57128b4..09e847c 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -135,7 +135,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; @@ -372,7 +372,7 @@ private function skipEmptyLines() private function resolveCommands(string $value, array $loadedVars): string { - if (false === strpos($value, '$')) { + if (!str_contains($value, '$')) { return $value; } @@ -408,7 +408,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; } } @@ -426,7 +426,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; } @@ -461,7 +461,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 a6f7fdd..037d039 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=7.1.3" + "php": ">=7.1.3", + "symfony/polyfill-php80": "^1.16" }, "require-dev": { "symfony/process": "^3.4.2|^4.0|^5.0"