mirror of
https://github.com/v2board/v2board.git
synced 2024-11-13 11:09:11 +08:00
optimization install
This commit is contained in:
parent
f7558fecc7
commit
406f1ee80d
@ -109,6 +109,30 @@ class V2boardInstall extends Command
|
|||||||
|
|
||||||
private function saveToEnv($data = [])
|
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) {
|
foreach($data as $key => $value) {
|
||||||
set_env_var($key, $value);
|
set_env_var($key, $value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user