From 8baa466782773e123938171326e4115fff93b4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Carodej?= Date: Tue, 12 Apr 2022 11:10:38 +0200 Subject: [PATCH] update for setEnvironmentValue function --- src/Support/helpers.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Support/helpers.php b/src/Support/helpers.php index 09b9ce6e..59d1e9bb 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -210,19 +210,23 @@ if (! function_exists('setEnvironmentValue')) { if (count($values) > 0) { foreach ($values as $envKey => $envValue) { + $str .= "\n"; // In case the searched variable is in the last line without \n $keyPosition = strpos($str, "{$envKey}="); - $endOfLinePosition = strpos($str, "\n", $keyPosition); - $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); - // If key does not exist, add it - $str = str_replace($oldLine, "{$envKey}={$envValue}", $str); + if ($keyPosition) { + $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); - return ! (! file_put_contents($envFile, $str)); + return file_put_contents($envFile, $str); } }