diff --git a/app/Config.php b/app/Config.php index 904467c..96f367b 100644 --- a/app/Config.php +++ b/app/Config.php @@ -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)) { diff --git a/app/DB.php b/app/DB.php index 324b73e..3a5f596 100644 --- a/app/DB.php +++ b/app/DB.php @@ -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 diff --git a/app/ExceptionHandler.php b/app/ExceptionHandler.php index 2674890..e293fc9 100644 --- a/app/ExceptionHandler.php +++ b/app/ExceptionHandler.php @@ -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 diff --git a/sakura.php b/sakura.php index 25e9a93..b894038 100644 --- a/sakura.php +++ b/sakura.php @@ -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'));