move framework files to app/Core directory

This commit is contained in:
printempw 2016-08-25 22:44:03 +08:00
parent e1525cfad4
commit dddd66d49e
32 changed files with 92 additions and 107 deletions

View File

@ -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, '请求的材质文件已经被删除');

View File

@ -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, '请求的材质文件已经被删除');
}

View File

@ -1,10 +1,10 @@
<?php
namespace App\Services;
namespace Blessing;
use Illuminate\Database\Capsule\Manager as Capsule;
use App\Services\Schema;
use App\Exceptions\E;
use \Illuminate\Database\Capsule\Manager as Capsule;
use \Blessing\Database\Schema;
use \App\Exceptions\E;
class Config
{

View File

@ -1,9 +1,9 @@
<?php
namespace Blessing\Foundation;
namespace Blessing\Database;
use \App\Exceptions\E;
use \App\Services\Config;
use \Blessing\Config;
/**
* Light-weight database helper

View File

@ -1,6 +1,8 @@
<?php
namespace App\Services;
namespace Blessing\Database;
use Blessing\Storage;
class Migration
{
@ -18,7 +20,7 @@ class Migration
{
if (strpos($method, 'import') !== false) {
$filename = BASE_DIR."/setup/migrations/".snake_case($method).".php";
if (Storage::exist($filename)) {
if (Storage::exists($filename)) {
return require $filename;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Services;
namespace Blessing\Database;
use Illuminate\Database\Capsule\Manager as Capsule;

View File

@ -3,7 +3,7 @@
namespace Blessing\Foundation;
use \Illuminate\Container\Container;
use \App\Services\Config;
use \Blessing\Config;
class Application extends Container
{
@ -15,6 +15,20 @@ class Application extends Container
* @return void
*/
public function run()
{
$this->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();
}
/**

View File

@ -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` 文件夹已被删除,请重新运行 <a href='./setup'>安装程序</a>,或者手动放置一个。", -1, true);
}
if (\App::version() != \App\Services\Option::get('version', '')) {
if (\App::version() != Option::get('version', '')) {
Http::redirect(Http::getBaseUrl().'/setup/update.php');
exit;
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Services;
namespace Blessing;
class Http
{
@ -8,18 +8,18 @@ class Http
* HTTP redirect
*
* @param string $url
* @param string $msg Write message to session
* @param boolean $use_js Use javascript to redirect
* @param string $msg Write message to session
* @return void
*/
public static function redirect($url, $msg = "", $use_js = false)
public static function redirect($url, $msg = "")
{
if ($msg != "") $_SESSION['msg'] = $msg;
if ($msg !== "") $_SESSION['msg'] = $msg;
if ($use_js)
echo "<script>window.location = '$url';</script>";
else
if (!headers_sent()) {
header('Location: '.$url);
} else {
echo "<meta http-equiv='Refresh' content='0; URL=$url'>";
}
exit;
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Services;
namespace Blessing;
use PHPMailer;

View File

@ -1,8 +1,8 @@
<?php
namespace App\Services;
namespace Blessing;
use Illuminate\Database\Eloquent\Model;
use \Illuminate\Database\Eloquent\Model;
use \Exception;
class Option

View File

@ -1,6 +1,6 @@
<?php
namespace App\Services;
namespace Blessing;
class Storage
{
@ -10,7 +10,7 @@ class Storage
* @param string $filename
* @return string|bool
*/
public static function read($filename)
public static function get($filename)
{
$result = file_get_contents($filename, 'r');
if (false === $result) {
@ -19,7 +19,7 @@ class Storage
return $result;
}
public static function exist($filename)
public static function exists($filename)
{
return file_exists($filename);
}
@ -39,7 +39,7 @@ class Storage
public static function size($filename)
{
if (self::exist($filename)) {
if (self::exists($filename)) {
return filesize($filename);
} else {
return 0;
@ -54,7 +54,7 @@ class Storage
*/
public static function remove($filename)
{
if (file_exists($filename)) {
if (self::exists($filename)) {
return unlink($filename);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Services;
namespace Blessing;
/**
* Just a wrapper for Blade template engine

View File

@ -84,13 +84,13 @@ class Player
if ($this->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, '请求的贴图已被删除。');
}

View File

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

View File

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

View File

@ -15,7 +15,7 @@
"autoload": {
"psr-4": {
"App\\": "app/",
"Blessing\\": "app/Blessing"
"Blessing\\": "app/Core"
},
"classmap": [
"app/Models"

View File

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

View File

@ -19,8 +19,6 @@
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<div class="info-box">
@ -58,7 +56,7 @@
<span class="info-box-icon bg-yellow"><i class="fa fa-hdd-o"></i></span>
<div class="info-box-content">
<span class="info-box-text">占用空间大小</span>
<?php $size = \DB::table('textures')->fetchArray("SELECT SUM(`size`) AS total_size FROM `{table}` WHERE 1")['total_size']; ?>
<?php $size = \DB::table('textures')->fetchArray("SELECT SUM(`size`) AS total_size FROM `{table}` WHERE 1")['total_size'] ?: 0; ?>
<span class="info-box-number">{{ $size > 1024 ? round($size / 1024, 1)."MB" : $size."KB" }}</span>
</div><!-- /.info-box-content -->
</div><!-- /.info-box -->

View File

@ -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']} 不存在");
}
}

View File

@ -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']} 不存在");
}
}

View File

@ -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']} 不存在");
}
}

View File

@ -3,7 +3,7 @@
@section('content')
<h1>升级成功</h1>
<p>数据库升级成功,欢迎使用 Blessing Skin Server {{ App::getVersion() }}</p>
<p>数据库升级成功,欢迎使用 Blessing Skin Server {{ App::version() }}</p>
<p class="step">
<a href="../" class="button button-large">首页</a>

View File

@ -3,7 +3,7 @@
@section('content')
<h1>还差一小步</h1>
<p>欢迎升级至 Blessing Skin Server {{ App::getVersion() }}</p>
<p>欢迎升级至 Blessing Skin Server {{ App::version() }}</p>
<p>我们需要升级您的数据库,点击下一步以继续。</p>
<p class="step">

View File

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

View File

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

View File

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

View File

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

View File

@ -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'])) {

View File

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