Refactoring: moved application bootstrapping to bootstrap.php

This commit is contained in:
Igor Scheller 2018-01-16 19:56:05 +01:00
parent 78cddecef3
commit e44ba84561
2 changed files with 39 additions and 32 deletions

37
includes/application.php Normal file
View File

@ -0,0 +1,37 @@
<?php
use Engelsystem\Application;
use Engelsystem\Config\Config;
use Engelsystem\Exceptions\Handler;
use Engelsystem\Exceptions\Handlers\HandlerInterface;
/**
* Include the autoloader
*/
require_once __DIR__ . '/autoload.php';
/**
* Initialize and bootstrap the application
*/
$app = new Application(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'));
$appConfig = $app->make(Config::class);
$appConfig->set(require config_path('app.php'));
$app->bootstrap($appConfig);
/**
* Configure application
*/
date_default_timezone_set($app->get('config')->get('timezone'));
if (config('environment') == 'development') {
$errorHandler = $app->get('error.handler');
$errorHandler->setEnvironment(Handler::ENV_DEVELOPMENT);
$app->bind(HandlerInterface::class, 'error.handler.development');
ini_set('display_errors', true);
error_reporting(E_ALL);
} else {
ini_set('display_errors', false);
}

View File

@ -1,14 +1,9 @@
<?php <?php
use Engelsystem\Application;
use Engelsystem\Config\Config;
use Engelsystem\Exceptions\Handler;
use Engelsystem\Exceptions\Handlers\HandlerInterface;
/** /**
* This file includes all needed functions, connects to the db etc. * Bootstrap application
*/ */
require_once __DIR__ . '/autoload.php'; require __DIR__ . '/application.php';
/** /**
@ -17,31 +12,6 @@ require_once __DIR__ . '/autoload.php';
require __DIR__ . '/includes.php'; require __DIR__ . '/includes.php';
/**
* Initialize and bootstrap the application
*/
$app = new Application(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'));
$appConfig = $app->make(Config::class);
$appConfig->set(require config_path('app.php'));
$app->bootstrap($appConfig);
/**
* Configure application
*/
date_default_timezone_set($app->get('config')->get('timezone'));
if (config('environment') == 'development') {
$errorHandler = $app->get('error.handler');
$errorHandler->setEnvironment(Handler::ENV_DEVELOPMENT);
$app->bind(HandlerInterface::class, 'error.handler.development');
ini_set('display_errors', true);
error_reporting(E_ALL);
} else {
ini_set('display_errors', false);
}
/** /**
* Check for maintenance * Check for maintenance
*/ */