2016-01-21 19:03:39 +08:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 22:01:57 +08:00
|
|
|
* Bootstrap file of Blessing Skin Server
|
2016-01-21 19:03:39 +08:00
|
|
|
*/
|
2016-07-21 22:01:57 +08:00
|
|
|
namespace App;
|
2016-02-10 15:20:13 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
// BASE_DIR
|
|
|
|
define('BASE_DIR', __DIR__);
|
|
|
|
|
|
|
|
// Autoloader
|
|
|
|
require BASE_DIR.'/vendor/autoload.php';
|
|
|
|
|
|
|
|
// Load dotenv configuration
|
|
|
|
$dotenv = new \Dotenv\Dotenv(BASE_DIR);
|
|
|
|
$dotenv->load();
|
2016-04-03 11:28:47 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
define('SALT', $_ENV['SALT']);
|
2016-04-03 11:28:47 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
if ($_ENV['APP_DEBUG'] !== "false") {
|
|
|
|
// whoops: php errors for cool kids
|
|
|
|
$whoops = new \Whoops\Run;
|
|
|
|
$handler = ($_SERVER['REQUEST_METHOD'] == "GET") ?
|
|
|
|
new \Whoops\Handler\PrettyPageHandler : new \Whoops\Handler\PlainTextHandler;
|
|
|
|
$whoops->pushHandler($handler);
|
|
|
|
$whoops->register();
|
|
|
|
}
|
2016-01-22 16:21:09 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
$services = require BASE_DIR.'/config/services.php';
|
|
|
|
foreach ($services as $facade => $class) {
|
|
|
|
class_alias($class, $facade);
|
|
|
|
}
|
2016-01-22 16:21:09 +08:00
|
|
|
|
2016-07-22 08:55:41 +08:00
|
|
|
/**
|
|
|
|
* URL ends with slash will cause many reference problems
|
|
|
|
*/
|
|
|
|
if (\Http::getUri() != "/" && substr(\Http::getUri(), -1) == "/")
|
|
|
|
{
|
|
|
|
die(\Http::getUri());
|
|
|
|
$url = substr(\Http::getCurrentUrl(), 0, -1);
|
|
|
|
\Http::redirect($url);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
// Check database config
|
|
|
|
$db_config = require BASE_DIR.'/config/database.php';
|
|
|
|
\Database::checkConfig($db_config);
|
2016-01-22 16:21:09 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
// Boot Eloquent ORM
|
|
|
|
$capsule = new \Illuminate\Database\Capsule\Manager;
|
|
|
|
$capsule->addConnection($db_config);
|
|
|
|
$capsule->bootEloquent();
|
2016-01-22 16:21:09 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
session_start();
|
2016-01-22 16:21:09 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
\Pecee\SimpleRouter\SimpleRouter::group([
|
2016-07-22 08:55:41 +08:00
|
|
|
'exceptionHandler' => 'App\Exceptions\RouterExceptionHandler'
|
2016-07-21 22:01:57 +08:00
|
|
|
], function() {
|
|
|
|
require BASE_DIR.'/config/routes.php';
|
|
|
|
});
|
2016-04-11 17:02:20 +08:00
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
// Start route dispatching
|
|
|
|
\Pecee\SimpleRouter\SimpleRouter::start('App\Controllers');
|