From b788b77236d10faf13395899ba03f4cc88f20472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Violet=5Fice=E7=B4=AB=E5=86=B0?= Date: Fri, 18 Sep 2020 19:14:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E8=A3=85=E7=94=9F?= =?UTF-8?q?=E6=88=90Env=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Install.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/application/admin/command/Install.php b/application/admin/command/Install.php index 835269dea..5a36ab197 100644 --- a/application/admin/command/Install.php +++ b/application/admin/command/Install.php @@ -215,6 +215,21 @@ class Install extends Command throw new Exception(__('The current permissions are insufficient to write the file %s', 'application/database.php')); } + // 生成Env配置文件 + $envFile = ROOT_PATH . '.env.sample'; + $envStr = @file_get_contents($envFile); + $callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) { + $field = "mysql" . ucfirst($matches[1]); + $replace = $$field; + return "{$matches[1]} = {$replace}" . PHP_EOL; + }; + $envConf = preg_replace_callback('/(hostname|database|username|password|hostport|prefix)\s*=\s*(.*?)\n/', $callback, $envStr); + + $result = @file_put_contents(ROOT_PATH . '.env', $envConf); + if (!$result) { + throw new Exception(__('The current permissions are insufficient to write the file %s', '.env')); + } + // 变更默认管理员密码 $adminPassword = $adminPassword ? $adminPassword : Random::alnum(8); $adminEmail = $adminEmail ? $adminEmail : "admin@admin.com"; -- Gitee