From 98505984e1a3a8db4e83cf0d0f5cccbb99781ba8 Mon Sep 17 00:00:00 2001 From: printempw Date: Wed, 24 Aug 2016 22:43:04 +0800 Subject: [PATCH] move framework files to App/Blessing --- app/Blessing/Facades/App.php | 21 ++++++++++++++ app/Blessing/Facades/DB.php | 18 ++++++++++++ .../Foundation}/Application.php | 23 +++++++++++---- .../Foundation}/Boot.php | 20 ++++++++++--- .../Foundation}/Database.php | 29 ++++--------------- app/Controllers/AdminController.php | 2 +- app/Services/PluginManager.php | 11 +++++++ composer.json | 3 +- config/services.php | 6 ++-- index.php | 2 +- resources/views/admin/update.tpl | 2 +- setup/index.php | 2 +- setup/migrations/index.php | 2 +- setup/update.php | 2 +- 14 files changed, 99 insertions(+), 44 deletions(-) create mode 100644 app/Blessing/Facades/App.php create mode 100644 app/Blessing/Facades/DB.php rename app/{Services => Blessing/Foundation}/Application.php (61%) rename app/{Services => Blessing/Foundation}/Boot.php (85%) rename app/{Services => Blessing/Foundation}/Database.php (90%) create mode 100644 app/Services/PluginManager.php diff --git a/app/Blessing/Facades/App.php b/app/Blessing/Facades/App.php new file mode 100644 index 00000000..fafc1f5b --- /dev/null +++ b/app/Blessing/Facades/App.php @@ -0,0 +1,21 @@ +version)) { + $config = require BASE_DIR."/config/app.php"; + $this->version = $config['version']; + } + return $this->version; } } diff --git a/app/Services/Boot.php b/app/Blessing/Foundation/Boot.php similarity index 85% rename from app/Services/Boot.php rename to app/Blessing/Foundation/Boot.php index 84bbd4e6..5425aa95 100644 --- a/app/Services/Boot.php +++ b/app/Blessing/Foundation/Boot.php @@ -1,11 +1,14 @@ instance('app', $app); + $app->bind('manager', \App\Services\PluginManager::class); + $app->bind('db', \Blessing\Foundation\Database::class); + } + public static function setTimeZone($timezone = 'Asia/Shanghai') { // set default time zone, UTC+8 for default @@ -39,7 +51,7 @@ class Boot throw new E("检测到 `textures` 文件夹已被删除,请重新运行 安装程序,或者手动放置一个。", -1, true); } - if (Application::getVersion() != Option::get('version', '')) { + if (\App::version() != \App\Services\Option::get('version', '')) { Http::redirect(Http::getBaseUrl().'/setup/update.php'); exit; } diff --git a/app/Services/Database.php b/app/Blessing/Foundation/Database.php similarity index 90% rename from app/Services/Database.php rename to app/Blessing/Foundation/Database.php index 766017f0..937c134a 100644 --- a/app/Services/Database.php +++ b/app/Blessing/Foundation/Database.php @@ -1,35 +1,16 @@ */ -class DatabaseHelper +class Database { /** * Instance of MySQLi @@ -79,7 +60,7 @@ class DatabaseHelper public function table($table_name, $no_prefix = false) { - if (Utils::convertString($table_name) == $table_name) { + if (mysql_escape_string($table_name) == $table_name) { $this->table_name = $no_prefix ? $table_name : $this->config['prefix'].$table_name; return $this; } else { diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index b4790c3e..49bdd17e 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(\App::getVersion()); + $updater = new \Updater(\App::version()); if ($updater->newVersionAvailable()) { View::json([ 'new_version_available' => true, diff --git a/app/Services/PluginManager.php b/app/Services/PluginManager.php new file mode 100644 index 00000000..78ab5a56 --- /dev/null +++ b/app/Services/PluginManager.php @@ -0,0 +1,11 @@ + 'App\Services\View', - 'Database' => 'App\Services\Database', + 'DB' => 'Blessing\Facades\DB', 'Option' => 'App\Services\Option', 'Utils' => 'App\Services\Utils', 'Validate' => 'App\Services\Validate', @@ -23,7 +23,7 @@ return [ 'Updater' => 'App\Services\Updater', 'Config' => 'App\Services\Config', 'Schema' => 'App\Services\Schema', - 'Boot' => 'App\Services\Boot', + 'Boot' => 'Blessing\Foundation\Boot', 'Migration' => 'App\Services\Migration', - 'App' => 'App\Services\Application' + 'App' => 'Blessing\Facades\App' ]; diff --git a/index.php b/index.php index a89095c0..bbbdfaea 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(); +$app = new Blessing\Foundation\Application(); // Start Application $app->run(); diff --git a/resources/views/admin/update.tpl b/resources/views/admin/update.tpl index 3ca3f8e4..dc26e254 100644 --- a/resources/views/admin/update.tpl +++ b/resources/views/admin/update.tpl @@ -14,7 +14,7 @@ - +
diff --git a/setup/index.php b/setup/index.php index bbbaf880..fd6d5f5e 100644 --- a/setup/index.php +++ b/setup/index.php @@ -10,7 +10,7 @@ define('BASE_DIR', dirname(dirname(__FILE__))); require BASE_DIR.'/vendor/autoload.php'; // Boot Services -App\Services\Boot::loadServices(); +Blessing\Foundation\Boot::loadServices(); Config::checkPHPVersion(); Boot::loadDotEnv(BASE_DIR); Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler); diff --git a/setup/migrations/index.php b/setup/migrations/index.php index fc208d37..2ee094a0 100644 --- a/setup/migrations/index.php +++ b/setup/migrations/index.php @@ -10,7 +10,7 @@ define('BASE_DIR', dirname(dirname(dirname(__FILE__)))); require BASE_DIR.'/vendor/autoload.php'; // Boot Services -App\Services\Boot::loadServices(); +Blessing\Foundation\Boot::loadServices(); Config::checkPHPVersion(); Boot::loadDotEnv(BASE_DIR); Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler); diff --git a/setup/update.php b/setup/update.php index 059bbf38..d9b1df87 100644 --- a/setup/update.php +++ b/setup/update.php @@ -10,7 +10,7 @@ define('BASE_DIR', dirname(dirname(__FILE__))); require BASE_DIR.'/vendor/autoload.php'; // Boot Services -App\Services\Boot::loadServices(); +Blessing\Foundation\Boot::loadServices(); Config::checkPHPVersion(); Boot::loadDotEnv(BASE_DIR); Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);