From 406f1ee80d21c62e47599c9698042fd4e40b9a58 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Sat, 8 Feb 2020 15:48:25 +0800 Subject: [PATCH] optimization install --- app/Console/Commands/V2boardInstall.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/Console/Commands/V2boardInstall.php b/app/Console/Commands/V2boardInstall.php index 05bf3ecd..ea15c403 100644 --- a/app/Console/Commands/V2boardInstall.php +++ b/app/Console/Commands/V2boardInstall.php @@ -109,6 +109,30 @@ class V2boardInstall extends Command private function saveToEnv($data = []) { + function set_env_var($key, $value) + { + if (! is_bool(strpos($value, ' '))) { + $value = '"' . $value . '"'; + } + $key = strtoupper($key); + + $envPath = app()->environmentFilePath(); + $contents = file_get_contents($envPath); + + preg_match("/^{$key}=[^\r\n]*/m", $contents, $matches); + + $oldValue = count($matches) ? $matches[0] : ''; + + if ($oldValue) { + $contents = str_replace("{$oldValue}", "{$key}={$value}", $contents); + } else { + $contents = $contents . "\n{$key}={$value}\n"; + } + + $file = fopen($envPath, 'w'); + fwrite($file, $contents); + return fclose($file); + } foreach($data as $key => $value) { set_env_var($key, $value); }