diff --git a/app/Controllers/SkinlibController.php b/app/Controllers/SkinlibController.php index 8962df89..79ac0062 100644 --- a/app/Controllers/SkinlibController.php +++ b/app/Controllers/SkinlibController.php @@ -97,7 +97,7 @@ class SkinlibController extends BaseController if (!isset($_GET['tid'])) Http::abort(404, 'No specified tid.'); $texture = Texture::find($_GET['tid']); - if (!$texture || $texture && !\Storage::exist(BASE_DIR."/textures/".$texture->hash)) { + if (!$texture || $texture && !\Storage::exists(BASE_DIR."/textures/".$texture->hash)) { if (Option::get('auto_del_invalid_texture') == "1") { if ($texture) $texture->delete(); Http::abort(404, '请求的材质文件已经被删除'); diff --git a/app/Controllers/TextureController.php b/app/Controllers/TextureController.php index 143e210e..2f4e6cc5 100644 --- a/app/Controllers/TextureController.php +++ b/app/Controllers/TextureController.php @@ -87,7 +87,7 @@ class TextureController extends BaseController if ($t = Texture::find($tid)) { $filename = BASE_DIR."/textures/".$t->hash; - if (\Storage::exist($filename)) { + if (\Storage::exists($filename)) { header('Content-Type: image/png'); if ($t->type == "cape") { @@ -121,9 +121,9 @@ class TextureController extends BaseController if ($t = Texture::find($tid)) { $fname = BASE_DIR."/textures/".$t->hash; - if (\Storage::exist($fname)) { + if (\Storage::exists($fname)) { header('Content-Type: image/png'); - echo \Storage::read($fname); + echo \Storage::get($fname); } else { Http::abort(404, '请求的材质文件已经被删除'); } diff --git a/app/Services/Config.php b/app/Core/Config.php similarity index 93% rename from app/Services/Config.php rename to app/Core/Config.php index 43990cf9..7b418afa 100644 --- a/app/Services/Config.php +++ b/app/Core/Config.php @@ -1,10 +1,10 @@ boot(); + + // Register Error Handler + Boot::registerErrorHandler(); + + // Redirect if not installed + Boot::checkInstallation(); + + // Start Route Dispatching + Boot::bootRouter(); + } + + public function boot() { // Load Aliases Boot::loadServices(); @@ -31,20 +45,11 @@ class Application extends Container // 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::bootRouter(); } /** diff --git a/app/Blessing/Foundation/Boot.php b/app/Core/Foundation/Boot.php similarity index 95% rename from app/Blessing/Foundation/Boot.php rename to app/Core/Foundation/Boot.php index 5425aa95..9c753620 100644 --- a/app/Blessing/Foundation/Boot.php +++ b/app/Core/Foundation/Boot.php @@ -7,8 +7,9 @@ use \Illuminate\Support\Facades\Facade; use \Pecee\SimpleRouter\SimpleRouter as Router; use \App\Exceptions\ExceptionHandler; use \App\Exceptions\E; -use \App\Services\Config; -use \App\Services\Http; +use \Blessing\Config; +use \Blessing\Option; +use \Blessing\Http; class Boot { @@ -26,7 +27,7 @@ class Boot $app->instance('app', $app); $app->bind('manager', \App\Services\PluginManager::class); - $app->bind('db', \Blessing\Foundation\Database::class); + $app->bind('db', \Blessing\Database\Database::class); } public static function setTimeZone($timezone = 'Asia/Shanghai') @@ -51,7 +52,7 @@ class Boot throw new E("检测到 `textures` 文件夹已被删除,请重新运行 安装程序,或者手动放置一个。", -1, true); } - if (\App::version() != \App\Services\Option::get('version', '')) { + if (\App::version() != Option::get('version', '')) { Http::redirect(Http::getBaseUrl().'/setup/update.php'); exit; } diff --git a/app/Services/Http.php b/app/Core/Http.php similarity index 86% rename from app/Services/Http.php rename to app/Core/Http.php index 1ad8f28e..e03a7de5 100644 --- a/app/Services/Http.php +++ b/app/Core/Http.php @@ -1,6 +1,6 @@ window.location = '$url';"; - else + if (!headers_sent()) { header('Location: '.$url); + } else { + echo ""; + } exit; } diff --git a/app/Services/Mail.php b/app/Core/Mail.php similarity index 98% rename from app/Services/Mail.php rename to app/Core/Mail.php index d31c78fe..a866b612 100644 --- a/app/Services/Mail.php +++ b/app/Core/Mail.php @@ -1,6 +1,6 @@ getTexture($type) != "") { $filename = BASE_DIR."/textures/".$this->getTexture($type); - if (\Storage::exist($filename)) { + if (\Storage::exists($filename)) { header('Content-Type: image/png'); // Cache friendly header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->getLastModified()).' GMT'); header('Content-Length: '.filesize($filename)); - return \Storage::read($filename); + return \Storage::get($filename); } else { \Http::abort(404, '请求的贴图已被删除。'); } diff --git a/app/Services/Utils.php b/app/Services/Utils.php index 309b1f3e..ba2b0865 100644 --- a/app/Services/Utils.php +++ b/app/Services/Utils.php @@ -81,7 +81,7 @@ class Utils public static function getAvatarFname(\App\Models\User $user) { $fname = base64_encode($user->email).".png"; - if (Option::get('avatar_query_string')) { + if (\Option::get('avatar_query_string')) { $fname .= '?v='.$user->getAvatarId(); } return $fname; diff --git a/app/Services/Validate.php b/app/Services/Validate.php index 84fa03da..0d5bdf4a 100644 --- a/app/Services/Validate.php +++ b/app/Services/Validate.php @@ -35,7 +35,7 @@ class Validate public static function playerName($player_name) { - $regx = (Option::get('allow_chinese_playername') == "1") ? + $regx = (\Option::get('allow_chinese_playername') == "1") ? "/^([A-Za-z0-9\x{4e00}-\x{9fa5}_]+)$/u" : "/^([A-Za-z0-9_]+)$/"; return preg_match($regx, $player_name); } diff --git a/composer.json b/composer.json index 56a4c573..e492aaf2 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "autoload": { "psr-4": { "App\\": "app/", - "Blessing\\": "app/Blessing" + "Blessing\\": "app/Core" }, "classmap": [ "app/Models" diff --git a/config/services.php b/config/services.php index ba0af74e..4bf8c293 100644 --- a/config/services.php +++ b/config/services.php @@ -11,19 +11,19 @@ */ return [ - 'View' => 'App\Services\View', + 'View' => 'Blessing\View', 'DB' => 'Blessing\Facades\DB', - 'Option' => 'App\Services\Option', + 'Option' => 'Blessing\Option', 'Utils' => 'App\Services\Utils', 'Validate' => 'App\Services\Validate', - 'Http' => 'App\Services\Http', - 'Mail' => 'App\Services\Mail', - 'Storage' => 'App\Services\Storage', + 'Http' => 'Blessing\Http', + 'Mail' => 'Blessing\Mail', + 'Storage' => 'Blessing\Storage', 'Minecraft' => 'App\Services\Minecraft', 'Updater' => 'App\Services\Updater', - 'Config' => 'App\Services\Config', - 'Schema' => 'App\Services\Schema', + 'Config' => 'Blessing\Config', + 'Schema' => 'Blessing\Database\Schema', 'Boot' => 'Blessing\Foundation\Boot', - 'Migration' => 'App\Services\Migration', + 'Migration' => 'Blessing\Database\Migration', 'App' => 'Blessing\Facades\App' ]; diff --git a/resources/views/admin/index.tpl b/resources/views/admin/index.tpl index 259e996d..a74dfb73 100644 --- a/resources/views/admin/index.tpl +++ b/resources/views/admin/index.tpl @@ -19,8 +19,6 @@
- -
@@ -58,7 +56,7 @@
占用空间大小 - fetchArray("SELECT SUM(`size`) AS total_size FROM `{table}` WHERE 1")['total_size']; ?> + fetchArray("SELECT SUM(`size`) AS total_size FROM `{table}` WHERE 1")['total_size'] ?: 0; ?> {{ $size > 1024 ? round($size / 1024, 1)."MB" : $size."KB" }}
diff --git a/resources/views/setup/migrations/import-v2-both.tpl b/resources/views/setup/migrations/import-v2-both.tpl index efee3228..eddef450 100644 --- a/resources/views/setup/migrations/import-v2-both.tpl +++ b/resources/views/setup/migrations/import-v2-both.tpl @@ -71,7 +71,7 @@ if (Utils::convertString($_POST['v2_table_name']) != $_POST['v2_table_name']) Http::redirect('index.php?action=import-v2-both&step=1', "表名 {$_POST['v2_table_name']} 中含有无效字符"); - if (!Database::hasTable($_POST['v2_table_name'])) { + if (!DB::hasTable($_POST['v2_table_name'])) { Http::redirect('index.php?action=import-v2-both&step=1', "数据表 {$_POST['v2_table_name']} 不存在"); } } diff --git a/resources/views/setup/migrations/import-v2-textures.tpl b/resources/views/setup/migrations/import-v2-textures.tpl index 192dbd5e..e29cf7b8 100644 --- a/resources/views/setup/migrations/import-v2-textures.tpl +++ b/resources/views/setup/migrations/import-v2-textures.tpl @@ -81,7 +81,7 @@ if (Utils::convertString($_POST['v2_table_name']) != $_POST['v2_table_name']) Http::redirect('index.php?action=import-v2-textures&step=1', "表名 {$_POST['v2_table_name']} 中含有无效字符"); - if (!Database::hasTable($_POST['v2_table_name'])) { + if (!DB::hasTable($_POST['v2_table_name'])) { Http::redirect('index.php?action=import-v2-textures&step=1', "数据表 {$_POST['v2_table_name']} 不存在"); } } diff --git a/resources/views/setup/migrations/import-v2-users.tpl b/resources/views/setup/migrations/import-v2-users.tpl index 0faf670d..81e5a384 100644 --- a/resources/views/setup/migrations/import-v2-users.tpl +++ b/resources/views/setup/migrations/import-v2-users.tpl @@ -49,7 +49,7 @@ if (Utils::convertString($_POST['v2_table_name']) != $_POST['v2_table_name']) Http::redirect('index.php?action=import-v2-users&step=1', "表名 {$_POST['v2_table_name']} 中含有无效字符"); - if (!Database::hasTable($_POST['v2_table_name'])) { + if (!DB::hasTable($_POST['v2_table_name'])) { Http::redirect('index.php?action=import-v2-users&step=1', "数据表 {$_POST['v2_table_name']} 不存在"); } } diff --git a/resources/views/setup/updates/success.tpl b/resources/views/setup/updates/success.tpl index 647204ed..afb15e51 100644 --- a/resources/views/setup/updates/success.tpl +++ b/resources/views/setup/updates/success.tpl @@ -3,7 +3,7 @@ @section('content')

升级成功

-

数据库升级成功,欢迎使用 Blessing Skin Server {{ App::getVersion() }}!

+

数据库升级成功,欢迎使用 Blessing Skin Server {{ App::version() }}!

首页 diff --git a/resources/views/setup/updates/welcome.tpl b/resources/views/setup/updates/welcome.tpl index e9f05790..1bfd75f8 100644 --- a/resources/views/setup/updates/welcome.tpl +++ b/resources/views/setup/updates/welcome.tpl @@ -3,7 +3,7 @@ @section('content')

还差一小步

-

欢迎升级至 Blessing Skin Server {{ App::getVersion() }}!

+

欢迎升级至 Blessing Skin Server {{ App::version() }}!

我们需要升级您的数据库,点击下一步以继续。

diff --git a/setup/index.php b/setup/index.php index fd6d5f5e..5f60a832 100644 --- a/setup/index.php +++ b/setup/index.php @@ -9,20 +9,13 @@ define('BASE_DIR', dirname(dirname(__FILE__))); // Register Composer Auto Loader require BASE_DIR.'/vendor/autoload.php'; -// Boot Services -Blessing\Foundation\Boot::loadServices(); -Config::checkPHPVersion(); -Boot::loadDotEnv(BASE_DIR); +// Initialize Application +$app = new Blessing\Foundation\Application(); +$app->boot(); Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler); -Boot::startSession(); $db_config = Config::getDbConfig(); -// Boot Eloquent to make Schema available -if (Config::checkDbConfig($db_config)) { - Boot::bootEloquent($db_config); -} - // If already installed if (Config::checkTableExist($db_config)) { View::show('setup.locked'); @@ -46,7 +39,7 @@ switch ($step) { case 3: // check post - if (Validate::checkPost(['email', 'password', 'confirm-pwd'])) + if (Validate::checkPost(['email', 'password', 'confirm-pwd'], true)) { if ($_POST['password'] != $_POST['confirm-pwd']) Http::redirect('index.php?step=2', '确认密码不一致'); @@ -77,7 +70,7 @@ switch ($step) { $options = require "options.php"; $options['site_name'] = $_POST['sitename']; $options['site_url'] = Http::getBaseUrl(); - $options['version'] = App::getVersion(); + $options['version'] = App::version(); $options['announcement'] = str_replace('{version}', $options['version'], $options['announcement']); foreach ($options as $key => $value) { diff --git a/setup/migrations/import_v2_both.php b/setup/migrations/import_v2_both.php index 12e074bb..cd2fc09d 100644 --- a/setup/migrations/import_v2_both.php +++ b/setup/migrations/import_v2_both.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-08-18 17:46:19 * @Last Modified by: printempw - * @Last Modified time: 2016-08-21 09:41:14 + * @Last Modified time: 2016-08-25 22:34:35 */ use App\Models\UserModel; @@ -26,7 +26,7 @@ $texture_imported = 0; $texture_duplicated = 0; // use db helper instead of fat ORM in some operations :( -$db = Database::table($v2_table_name, true); +$db = DB::table($v2_table_name, true); $steps = ceil($db->getRecordNum() / 250); @@ -70,7 +70,7 @@ for ($i = 0; $i <= $steps; $i++) { $res = Texture::where('hash', $row["hash_$model"])->first(); - if ($res->isEmpty()) { + if (!$res) { $t = new Texture; $t->name = $name; diff --git a/setup/migrations/import_v2_textures.php b/setup/migrations/import_v2_textures.php index b3328391..b06f2ec6 100644 --- a/setup/migrations/import_v2_textures.php +++ b/setup/migrations/import_v2_textures.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-08-09 21:44:13 * @Last Modified by: printempw - * @Last Modified time: 2016-08-20 23:43:45 + * @Last Modified time: 2016-08-25 22:30:49 * * There are still some coupling relationships here but, * Just let it go :) @@ -18,7 +18,7 @@ $imported = 0; $duplicated = 0; // use db helper instead of fat ORM -$db = Database::table($v2_table_name, true); +$db = DB::table($v2_table_name, true); $steps = ceil($db->getRecordNum() / 250); diff --git a/setup/migrations/import_v2_users.php b/setup/migrations/import_v2_users.php index c6515c48..5653288a 100644 --- a/setup/migrations/import_v2_users.php +++ b/setup/migrations/import_v2_users.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-08-18 17:46:19 * @Last Modified by: printempw - * @Last Modified time: 2016-08-20 18:42:56 + * @Last Modified time: 2016-08-25 22:30:49 */ if (!defined('BASE_DIR')) exit('Permission denied.'); @@ -18,7 +18,7 @@ $imported = 0; $duplicated = 0; // use db helper instead of fat ORM -$db = Database::table($v2_table_name, true); +$db = DB::table($v2_table_name, true); $steps = ceil($db->getRecordNum() / 250); diff --git a/setup/migrations/index.php b/setup/migrations/index.php index 2ee094a0..a29cdade 100644 --- a/setup/migrations/index.php +++ b/setup/migrations/index.php @@ -9,20 +9,13 @@ define('BASE_DIR', dirname(dirname(dirname(__FILE__)))); // Register Composer Auto Loader require BASE_DIR.'/vendor/autoload.php'; -// Boot Services -Blessing\Foundation\Boot::loadServices(); -Config::checkPHPVersion(); -Boot::loadDotEnv(BASE_DIR); +// Initialize Application +$app = new Blessing\Foundation\Application(); +$app->boot(); Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler); -Boot::startSession(); $db_config = Config::getDbConfig(); -// Boot Eloquent to make Schema available -if (Config::checkDbConfig($db_config)) { - Boot::bootEloquent($db_config); -} - Boot::checkInstallation('../../setup/index.php'); if (isset($_COOKIE['uid']) && isset($_COOKIE['token'])) { diff --git a/setup/update.php b/setup/update.php index d9b1df87..ea293bf7 100644 --- a/setup/update.php +++ b/setup/update.php @@ -9,22 +9,15 @@ define('BASE_DIR', dirname(dirname(__FILE__))); // Register Composer Auto Loader require BASE_DIR.'/vendor/autoload.php'; -// Boot Services -Blessing\Foundation\Boot::loadServices(); -Config::checkPHPVersion(); -Boot::loadDotEnv(BASE_DIR); +// Initialize Application +$app = new Blessing\Foundation\Application(); +$app->boot(); Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler); -Boot::startSession(); $db_config = Config::getDbConfig(); -// Boot Eloquent to make Schema available -if (Config::checkDbConfig($db_config)) { - Boot::bootEloquent($db_config); -} - // If no update is available -if (App::getVersion() == Option::get('version', '')) { +if (App::version() == Option::get('version', '')) { View::show('setup.locked'); exit; } @@ -44,7 +37,7 @@ switch ($step) { preg_match('/update-(.*)-to-(.*).php/', $filename, $matches); if (isset($matches[2])) { - $update_script_exist = ($matches[2] == App::getVersion()); + $update_script_exist = ($matches[2] == App::version()); } else { continue; } @@ -56,7 +49,7 @@ switch ($step) { if (!$update_script_exist) { // if update script is not given - Option::set('version', App::getVersion()); + Option::set('version', App::version()); } View::show('setup.updates.success');