clean sakura.php up (a lot)

This commit is contained in:
flash 2016-10-07 19:55:50 +02:00
parent 9f494ee990
commit 6d0ec8d1e5
4 changed files with 25 additions and 34 deletions

View file

@ -24,12 +24,12 @@ class Config
private static $config = [];
/**
* Initialiser, parses the configuration.
* Loads and parses the configuration file.
* @throws ConfigNonExistentException
* @throws ConfigParseException
* @param string $path
*/
public static function init($path)
public static function load($path)
{
// Check if the configuration file exists
if (!file_exists($path)) {

View file

@ -17,6 +17,17 @@ use Illuminate\Database\Migrations\DatabaseMigrationRepository;
*/
class DB extends Manager
{
/**
* Start the database module.
* @param array $details
*/
public static function connect($details)
{
$capsule = new static;
$capsule->addConnection($details);
$capsule->setAsGlobal();
}
/**
* Gets the migration repository (surprise surprise).
* @return DatabaseMigrationRepository

View file

@ -23,6 +23,15 @@ class ExceptionHandler
*/
private static $disableTemplate = false;
/**
* Register as the error and exception handler.
*/
public static function register()
{
set_exception_handler([static::class, 'exception']);
set_error_handler([static::class, 'error']);
}
/**
* The entry point for set_exception_handler.
* @param Throwable $ex

View file

@ -6,37 +6,8 @@
namespace Sakura;
// Turn error reporting on regardless of anything
error_reporting(-1);
// Override expiration variables
ignore_user_abort(true);
set_time_limit(0);
// Set internal encoding method
mb_internal_encoding('utf-8');
// Check the PHP version
if (version_compare(phpversion(), '7.0.0', '<')) {
die('Sakura requires at least PHP 7.0.0, please upgrade to a newer PHP version.');
}
// Check if the composer autoloader exists
if (!file_exists('vendor/autoload.php')) {
die('Autoloader not found, did you run composer install?');
}
// Include the autoloader
require_once 'vendor/autoload.php';
// Register the handlers
set_exception_handler([ExceptionHandler::class, 'exception']);
set_error_handler([ExceptionHandler::class, 'error']);
// Load the configuration
Config::init(path('config/config.ini'));
// Start the database module
$capsule = new DB;
$capsule->addConnection(config('database'));
$capsule->setAsGlobal();
ExceptionHandler::register();
Config::load(path('config/config.ini'));
DB::connect(config('database'));