Skip to content

Commit

Permalink
allow new variables to be added to env
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Wojczal committed Jul 5, 2023
1 parent 999a2ab commit 732e3f5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docker/envs/envs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 732e3f5

Please sign in to comment.