From ab472d8fd2137856597121a08397aee06e6ad594 Mon Sep 17 00:00:00 2001 From: printempw Date: Wed, 10 Aug 2016 13:02:16 +0800 Subject: [PATCH] move boot procedure to Boot class --- app/Controllers/AdminController.php | 2 +- app/Services/Application.php | 37 ++++++----------------------- app/Services/Boot.php | 27 +++++++++++++++++++++ config/services.php | 31 ++++++++++++------------ index.php | 2 +- 5 files changed, 52 insertions(+), 47 deletions(-) diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index 604178e2..dec35b59 100644 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -38,7 +38,7 @@ class AdminController extends BaseController public function update() { if (\Utils::getValue('action', $_GET) == "check") { - $updater = new \Updater(\Application::getVersion()); + $updater = new \Updater(\App::getVersion()); if ($updater->newVersionAvailable()) { View::json([ 'new_version_available' => true, diff --git a/app/Services/Application.php b/app/Services/Application.php index d2060783..64db3c71 100644 --- a/app/Services/Application.php +++ b/app/Services/Application.php @@ -4,13 +4,6 @@ namespace App\Services; class Application { - protected $base_dir; - - public function __construct($dir) - { - $this->base_dir = $dir; - } - /** * Start Application * @@ -18,34 +11,18 @@ class Application */ public function run() { - // Load Aliases - Boot::loadServices(); - - // Check Runtime Environment - Boot::checkRuntimeEnv(); - - // Load dotenv Configuration - Boot::loadDotEnv($this->base_dir); - - // Register Error Handler - Boot::registerErrorHandler(); - - // Boot Eloquent ORM - Boot::bootEloquent(Config::getDbConfig()); - - // Redirect if not installed - Boot::checkInstallation(); - - // Start Session - Boot::startSession(); - - // Start Route Dispatching - Boot::bootRouter(); + Boot::start(); } + /** + * Get current app version + * + * @return string + */ public static function getVersion() { $config = require BASE_DIR."/config/app.php"; return $config['version']; } + } diff --git a/app/Services/Boot.php b/app/Services/Boot.php index a3c35575..2a4f0799 100644 --- a/app/Services/Boot.php +++ b/app/Services/Boot.php @@ -9,6 +9,33 @@ use App\Exceptions\E; class Boot { + public static function start() + { + // Load Aliases + self::loadServices(); + + // Check Runtime Environment + self::checkRuntimeEnv(); + + // Load dotenv Configuration + self::loadDotEnv(BASE_DIR); + + // Register Error Handler + self::registerErrorHandler(); + + // Boot Eloquent ORM + self::bootEloquent(Config::getDbConfig()); + + // Redirect if not installed + self::checkInstallation(); + + // Start Session + self::startSession(); + + // Start Route Dispatching + self::bootRouter(); + } + public static function loadDotEnv($dir) { if (Config::checkDotEnvExist()) { diff --git a/config/services.php b/config/services.php index 74342d61..425032fd 100644 --- a/config/services.php +++ b/config/services.php @@ -9,20 +9,21 @@ | the aliases are "lazy" loaded so they don't hinder performance. | */ + return [ - 'View' => 'App\Services\View', - 'Database' => 'App\Services\Database', - 'Option' => 'App\Services\Option', - 'Utils' => 'App\Services\Utils', - 'Validate' => 'App\Services\Validate', - 'Http' => 'App\Services\Http', - 'Mail' => 'App\Services\Mail', - 'Storage' => 'App\Services\Storage', - 'Minecraft' => 'App\Services\Minecraft', - 'Updater' => 'App\Services\Updater', - 'Config' => 'App\Services\Config', - 'Schema' => 'App\Services\Schema', - 'Boot' => 'App\Services\Boot', - 'Migration' => 'App\Services\Migration', - 'Application' => 'App\Services\Application' + 'View' => 'App\Services\View', + 'Database' => 'App\Services\Database', + 'Option' => 'App\Services\Option', + 'Utils' => 'App\Services\Utils', + 'Validate' => 'App\Services\Validate', + 'Http' => 'App\Services\Http', + 'Mail' => 'App\Services\Mail', + 'Storage' => 'App\Services\Storage', + 'Minecraft' => 'App\Services\Minecraft', + 'Updater' => 'App\Services\Updater', + 'Config' => 'App\Services\Config', + 'Schema' => 'App\Services\Schema', + 'Boot' => 'App\Services\Boot', + 'Migration' => 'App\Services\Migration', + 'App' => 'App\Services\Application' ]; diff --git a/index.php b/index.php index e372a78b..a89095c0 100755 --- a/index.php +++ b/index.php @@ -10,7 +10,7 @@ define('BASE_DIR', __DIR__); require BASE_DIR.'/vendor/autoload.php'; // Initialize Application -$app = new App\Services\Application(BASE_DIR); +$app = new App\Services\Application(); // Start Application $app->run();