move framework files to App/Blessing
This commit is contained in:
parent
875cff557d
commit
98505984e1
21
app/Blessing/Facades/App.php
Normal file
21
app/Blessing/Facades/App.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Blessing\Facades;
|
||||||
|
|
||||||
|
use \Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \Blessing\Foundation\Application
|
||||||
|
*/
|
||||||
|
class App extends Facade
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the registered name of the component.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'app';
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Blessing/Facades/DB.php
Normal file
18
app/Blessing/Facades/DB.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Blessing\Facades;
|
||||||
|
|
||||||
|
use \Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
class DB extends Facade
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the registered name of the component.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'db';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services;
|
namespace Blessing\Foundation;
|
||||||
|
|
||||||
class Application
|
use \Illuminate\Container\Container;
|
||||||
|
use \App\Services\Config;
|
||||||
|
|
||||||
|
class Application extends Container
|
||||||
{
|
{
|
||||||
|
private $version = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Application
|
* Start Application
|
||||||
*
|
*
|
||||||
|
|
@ -17,6 +22,9 @@ class Application
|
||||||
// Check Runtime Environment
|
// Check Runtime Environment
|
||||||
Boot::checkRuntimeEnv();
|
Boot::checkRuntimeEnv();
|
||||||
|
|
||||||
|
// Register Facades
|
||||||
|
Boot::registerFacades($this);
|
||||||
|
|
||||||
// Set Default Timezone to UTC+8
|
// Set Default Timezone to UTC+8
|
||||||
Boot::setTimeZone();
|
Boot::setTimeZone();
|
||||||
|
|
||||||
|
|
@ -40,14 +48,17 @@ class Application
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current app version
|
* Get the version number of the application.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getVersion()
|
public function version()
|
||||||
{
|
{
|
||||||
$config = require BASE_DIR."/config/app.php";
|
if (is_null($this->version)) {
|
||||||
return $config['version'];
|
$config = require BASE_DIR."/config/app.php";
|
||||||
|
$this->version = $config['version'];
|
||||||
|
}
|
||||||
|
return $this->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services;
|
namespace Blessing\Foundation;
|
||||||
|
|
||||||
use \Illuminate\Database\Capsule\Manager as Capsule;
|
use \Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use \Illuminate\Support\Facades\Facade;
|
||||||
use \Pecee\SimpleRouter\SimpleRouter as Router;
|
use \Pecee\SimpleRouter\SimpleRouter as Router;
|
||||||
use App\Exceptions\ExceptionHandler;
|
use \App\Exceptions\ExceptionHandler;
|
||||||
use App\Exceptions\E;
|
use \App\Exceptions\E;
|
||||||
|
use \App\Services\Config;
|
||||||
|
use \App\Services\Http;
|
||||||
|
|
||||||
class Boot
|
class Boot
|
||||||
{
|
{
|
||||||
|
|
@ -17,6 +20,15 @@ class Boot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function registerFacades(Application $app)
|
||||||
|
{
|
||||||
|
Facade::setFacadeApplication($app);
|
||||||
|
|
||||||
|
$app->instance('app', $app);
|
||||||
|
$app->bind('manager', \App\Services\PluginManager::class);
|
||||||
|
$app->bind('db', \Blessing\Foundation\Database::class);
|
||||||
|
}
|
||||||
|
|
||||||
public static function setTimeZone($timezone = 'Asia/Shanghai')
|
public static function setTimeZone($timezone = 'Asia/Shanghai')
|
||||||
{
|
{
|
||||||
// set default time zone, UTC+8 for default
|
// set default time zone, UTC+8 for default
|
||||||
|
|
@ -39,7 +51,7 @@ class Boot
|
||||||
throw new E("检测到 `textures` 文件夹已被删除,请重新运行 <a href='./setup'>安装程序</a>,或者手动放置一个。", -1, true);
|
throw new E("检测到 `textures` 文件夹已被删除,请重新运行 <a href='./setup'>安装程序</a>,或者手动放置一个。", -1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Application::getVersion() != Option::get('version', '')) {
|
if (\App::version() != \App\Services\Option::get('version', '')) {
|
||||||
Http::redirect(Http::getBaseUrl().'/setup/update.php');
|
Http::redirect(Http::getBaseUrl().'/setup/update.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
@ -1,35 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services;
|
namespace Blessing\Foundation;
|
||||||
|
|
||||||
use App\Exceptions\E;
|
use \App\Exceptions\E;
|
||||||
|
use \App\Services\Config;
|
||||||
/**
|
|
||||||
* Facade for DatabaseHelper
|
|
||||||
*/
|
|
||||||
class Database
|
|
||||||
{
|
|
||||||
public function __call($method, $args)
|
|
||||||
{
|
|
||||||
// Instantiate Helper
|
|
||||||
$instance = new DatabaseHelper;
|
|
||||||
// Call methods
|
|
||||||
return call_user_func_array([$instance, $method], $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function __callStatic($method, $args)
|
|
||||||
{
|
|
||||||
$instance = new DatabaseHelper;
|
|
||||||
return call_user_func_array([$instance, $method], $args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Light-weight database helper
|
* Light-weight database helper
|
||||||
*
|
*
|
||||||
* @author <h@prinzeugen.net>
|
* @author <h@prinzeugen.net>
|
||||||
*/
|
*/
|
||||||
class DatabaseHelper
|
class Database
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Instance of MySQLi
|
* Instance of MySQLi
|
||||||
|
|
@ -79,7 +60,7 @@ class DatabaseHelper
|
||||||
|
|
||||||
public function table($table_name, $no_prefix = false)
|
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;
|
$this->table_name = $no_prefix ? $table_name : $this->config['prefix'].$table_name;
|
||||||
return $this;
|
return $this;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -38,7 +38,7 @@ class AdminController extends BaseController
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
if (Utils::getValue('action', $_GET) == "check") {
|
if (Utils::getValue('action', $_GET) == "check") {
|
||||||
$updater = new \Updater(\App::getVersion());
|
$updater = new \Updater(\App::version());
|
||||||
if ($updater->newVersionAvailable()) {
|
if ($updater->newVersionAvailable()) {
|
||||||
View::json([
|
View::json([
|
||||||
'new_version_available' => true,
|
'new_version_available' => true,
|
||||||
|
|
|
||||||
11
app/Services/PluginManager.php
Normal file
11
app/Services/PluginManager.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
class PluginManager
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,8 @@
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/"
|
"App\\": "app/",
|
||||||
|
"Blessing\\": "app/Blessing"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"app/Models"
|
"app/Models"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'View' => 'App\Services\View',
|
'View' => 'App\Services\View',
|
||||||
'Database' => 'App\Services\Database',
|
'DB' => 'Blessing\Facades\DB',
|
||||||
'Option' => 'App\Services\Option',
|
'Option' => 'App\Services\Option',
|
||||||
'Utils' => 'App\Services\Utils',
|
'Utils' => 'App\Services\Utils',
|
||||||
'Validate' => 'App\Services\Validate',
|
'Validate' => 'App\Services\Validate',
|
||||||
|
|
@ -23,7 +23,7 @@ return [
|
||||||
'Updater' => 'App\Services\Updater',
|
'Updater' => 'App\Services\Updater',
|
||||||
'Config' => 'App\Services\Config',
|
'Config' => 'App\Services\Config',
|
||||||
'Schema' => 'App\Services\Schema',
|
'Schema' => 'App\Services\Schema',
|
||||||
'Boot' => 'App\Services\Boot',
|
'Boot' => 'Blessing\Foundation\Boot',
|
||||||
'Migration' => 'App\Services\Migration',
|
'Migration' => 'App\Services\Migration',
|
||||||
'App' => 'App\Services\Application'
|
'App' => 'Blessing\Facades\App'
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ define('BASE_DIR', __DIR__);
|
||||||
require BASE_DIR.'/vendor/autoload.php';
|
require BASE_DIR.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Initialize Application
|
// Initialize Application
|
||||||
$app = new App\Services\Application();
|
$app = new Blessing\Foundation\Application();
|
||||||
|
|
||||||
// Start Application
|
// Start Application
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
</h1>
|
</h1>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<?php $updater = new Updater(App::getVersion()); ?>
|
<?php $updater = new Updater(App::version()); ?>
|
||||||
<!-- Main content -->
|
<!-- Main content -->
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ define('BASE_DIR', dirname(dirname(__FILE__)));
|
||||||
require BASE_DIR.'/vendor/autoload.php';
|
require BASE_DIR.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Boot Services
|
// Boot Services
|
||||||
App\Services\Boot::loadServices();
|
Blessing\Foundation\Boot::loadServices();
|
||||||
Config::checkPHPVersion();
|
Config::checkPHPVersion();
|
||||||
Boot::loadDotEnv(BASE_DIR);
|
Boot::loadDotEnv(BASE_DIR);
|
||||||
Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);
|
Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ define('BASE_DIR', dirname(dirname(dirname(__FILE__))));
|
||||||
require BASE_DIR.'/vendor/autoload.php';
|
require BASE_DIR.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Boot Services
|
// Boot Services
|
||||||
App\Services\Boot::loadServices();
|
Blessing\Foundation\Boot::loadServices();
|
||||||
Config::checkPHPVersion();
|
Config::checkPHPVersion();
|
||||||
Boot::loadDotEnv(BASE_DIR);
|
Boot::loadDotEnv(BASE_DIR);
|
||||||
Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);
|
Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ define('BASE_DIR', dirname(dirname(__FILE__)));
|
||||||
require BASE_DIR.'/vendor/autoload.php';
|
require BASE_DIR.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Boot Services
|
// Boot Services
|
||||||
App\Services\Boot::loadServices();
|
Blessing\Foundation\Boot::loadServices();
|
||||||
Config::checkPHPVersion();
|
Config::checkPHPVersion();
|
||||||
Boot::loadDotEnv(BASE_DIR);
|
Boot::loadDotEnv(BASE_DIR);
|
||||||
Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);
|
Boot::registerErrorHandler(new \Whoops\Handler\PrettyPageHandler);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user