move boot procedure to Boot class

This commit is contained in:
printempw 2016-08-10 13:02:16 +08:00
parent 88f1ca4f23
commit ab472d8fd2
5 changed files with 52 additions and 47 deletions

View File

@ -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,

View File

@ -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'];
}
}

View File

@ -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()) {

View File

@ -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'
];

View File

@ -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();