diff --git a/app/Services/Boot.php b/app/Services/Boot.php
index 44a8a29c..6a5bd4c2 100644
--- a/app/Services/Boot.php
+++ b/app/Services/Boot.php
@@ -5,6 +5,7 @@ namespace App\Services;
use \Illuminate\Database\Capsule\Manager as Capsule;
use \Pecee\SimpleRouter\SimpleRouter as Router;
use App\Exceptions\ExceptionHandler;
+use App\Exceptions\E;
class Boot
{
@@ -19,7 +20,19 @@ class Boot
public static function checkRuntimeEnv()
{
Config::checkPHPVersion();
- Config::checkFolderExist();
+ Config::checkCache();
+ }
+
+ public static function checkInstallation()
+ {
+ if (!Config::checkTableExist()) {
+ Http::redirect('../setup/index.php');
+ }
+
+ if (!is_dir(BASE_DIR.'/textures/')) {
+ throw new E("检测到 `textures` 文件夹已被删除,请重新运行 安装程序,或者手动放置一个。", -1, true);
+ }
+ return true;
}
public static function loadServices()
@@ -49,10 +62,12 @@ class Boot
public static function bootEloquent(Array $config)
{
- $capsule = new Capsule;
- $capsule->addConnection($config);
- $capsule->setAsGlobal();
- $capsule->bootEloquent();
+ if (Config::checkDbConfig($config)) {
+ $capsule = new Capsule;
+ $capsule->addConnection($config);
+ $capsule->setAsGlobal();
+ $capsule->bootEloquent();
+ }
}
public static function startSession()
diff --git a/app/Services/Config.php b/app/Services/Config.php
index fea9182c..2261dbf4 100644
--- a/app/Services/Config.php
+++ b/app/Services/Config.php
@@ -42,7 +42,7 @@ class Config
return true;
}
- public static function checkTableExist(Array $config)
+ public static function checkTableExist()
{
$tables = ['users', 'closets', 'players', 'textures', 'options'];
@@ -56,11 +56,8 @@ class Config
return true;
}
- public static function checkFolderExist()
+ public static function checkCache()
{
- if (!is_dir(BASE_DIR."/textures/"))
- throw new E("根目录下未发现 `textures` 文件夹,请先运行 安装程序,或者手动放置一个。", -1, true);
-
$view_config = self::getViewConfig();
if (!is_dir($view_config['cache_path'])) {
diff --git a/index.php b/index.php
index ddca28a1..50cc5301 100755
--- a/index.php
+++ b/index.php
@@ -21,17 +21,11 @@ Boot::loadDotEnv(BASE_DIR);
// Register Error Handler
Boot::registerErrorHandler();
-$db_config = Config::getDbConfig();
-
// Boot Eloquent ORM
-if (Config::checkDbConfig($db_config)) {
- Boot::bootEloquent($db_config);
-}
+Boot::bootEloquent(Config::getDbConfig());
-// Redirect to Setup Page
-if (!Config::checkTableExist($db_config)) {
- Http::redirect('../setup/index.php');
-}
+// Redirect if not installed
+Boot::checkInstallation();
// Start Session
Boot::startSession();