update for setEnvironmentValue function

This commit is contained in:
Čarodej
2022-04-12 11:10:38 +02:00
parent 8df7794484
commit 8baa466782

View File

@@ -210,19 +210,23 @@ if (! function_exists('setEnvironmentValue')) {
if (count($values) > 0) { if (count($values) > 0) {
foreach ($values as $envKey => $envValue) { foreach ($values as $envKey => $envValue) {
$str .= "\n"; // In case the searched variable is in the last line without \n $str .= "\n"; // In case the searched variable is in the last line without \n
$keyPosition = strpos($str, "{$envKey}="); $keyPosition = strpos($str, "{$envKey}=");
$endOfLinePosition = strpos($str, "\n", $keyPosition);
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
// If key does not exist, add it if ($keyPosition) {
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str); $endOfLinePosition = strpos($str, "\n", $keyPosition);
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
} else {
$str .= "\n$envKey=$envValue";
}
} }
} }
$str = substr($str, 0, -1); $str = substr($str, 0, -1);
return ! (! file_put_contents($envFile, $str)); return file_put_contents($envFile, $str);
} }
} }