abstract Application class

This commit is contained in:
printempw 2016-08-08 22:19:12 +08:00
parent 2934273086
commit 2926f28add
6 changed files with 72 additions and 28 deletions

View File

@ -0,0 +1,51 @@
<?php
namespace App\Services;
class Application
{
protected $base_dir;
public function __construct($dir)
{
$this->base_dir = $dir;
}
/**
* Start Application
*
* @return void
*/
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();
}
public static function getVersion()
{
$config = require BASE_DIR."/config/app.php";
return $config['version'];
}
}

View File

@ -91,11 +91,7 @@ class Boot
], function() { ], function() {
require BASE_DIR.'/config/routes.php'; require BASE_DIR.'/config/routes.php';
}); });
}
public static function run()
{
self::bootRouter();
// Start Route Dispatching // Start Route Dispatching
Router::start('App\Controllers'); Router::start('App\Controllers');
} }

13
config/app.php Normal file
View File

@ -0,0 +1,13 @@
<?php
/*
|--------------------------------------------------------------------------
| Application Configuration
|--------------------------------------------------------------------------
|
| Here is the configs about the application.
|
*/
return [
'version' => '3.0.1',
'locale' => 'zh-cn'
];

View File

@ -9,26 +9,8 @@ define('BASE_DIR', __DIR__);
// Register Composer Auto Loader // Register Composer Auto Loader
require BASE_DIR.'/vendor/autoload.php'; require BASE_DIR.'/vendor/autoload.php';
// Load Aliases // Initialize Application
App\Services\Boot::loadServices(); $app = new App\Services\Application(BASE_DIR);
// Check Runtime Environment // Start Application
Boot::checkRuntimeEnv(); $app->run();
// Load dotenv Configuration
Boot::loadDotEnv(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::run();

View File

@ -77,6 +77,7 @@ switch ($step) {
$options = require "options.php"; $options = require "options.php";
$options['site_name'] = $_POST['sitename']; $options['site_name'] = $_POST['sitename'];
$options['site_url'] = Http::getBaseUrl(); $options['site_url'] = Http::getBaseUrl();
$options['version'] = Application::getVersion();
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
Option::add($key, $value); Option::add($key, $value);

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-29 11:53:11 * @Date: 2016-07-29 11:53:11
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-08-07 16:43:16 * @Last Modified time: 2016-08-08 21:51:58
*/ */
return [ return [
@ -29,5 +29,6 @@ return [
'score_per_storage' => '1', 'score_per_storage' => '1',
'score_per_player' => '100', 'score_per_player' => '100',
'sign_after_zero' => '0', 'sign_after_zero' => '0',
'avatar_query_string' => '0' 'avatar_query_string' => '0',
'version' => ''
]; ];