From 732e3f52897f9ef53370d89721fde36dbe341cd7 Mon Sep 17 00:00:00 2001 From: Mateusz Wojczal Date: Wed, 5 Jul 2023 12:00:07 +0200 Subject: [PATCH] allow new variables to be added to env --- docker/envs/envs.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docker/envs/envs.php b/docker/envs/envs.php index d27556fd..e7ea981b 100644 --- a/docker/envs/envs.php +++ b/docker/envs/envs.php @@ -11,9 +11,17 @@ function set_env(string $key, string $prev_value, string $new_value, string $env_path) { $new_value = preg_replace('/\s+/', '', $new_value); //replace special ch - $key = strtoupper($key); //force upper for security $env = file_get_contents($env_path); //fet .env file - $env = str_replace("$key=" . $prev_value, "$key=" . $new_value, $env); //replace value + $key = strtoupper($key); //force upper for security + $lines = explode("\n", $env); + for ($i = 0; $i < count($lines); $i++) { + + if (strpos(strtoupper($lines[$i]), $key) !== false) { + $lines[$i] = $key . "=" . $new_value; + } + } + + $env = implode("\n", $lines); $env = file_put_contents($env_path, $env); }