From 8506d6d27e3b926521007064abcdcc2f69c6aa06 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 21 Jan 2017 23:07:20 +0100 Subject: Refactoring: Config cleanup / moved to class --- includes/engelsystem_provider.php | 82 +++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 24 deletions(-) (limited to 'includes/engelsystem_provider.php') diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 3537f100..8a5723ef 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -1,5 +1,6 @@ set(require __DIR__ . '/../config/config.default.php'); + +if (file_exists(__DIR__ . '/../config/config.php')) { + $config->set(array_replace_recursive( + $config->get(null), + require __DIR__ . '/../config/config.php' + )); +} + +date_default_timezone_set($config->get('timezone')); + + +/** + * Check for maintenance + */ +if ($config->get('maintenance')) { + echo file_get_contents(__DIR__ . '/../public/maintenance.html'); + die(); +} + + +/** + * Register error handler + */ +$errorHandler = new ExceptionHandler(); +if (config('environment') == 'development') { + $errorHandler->setEnvironment(ExceptionHandler::ENV_DEVELOPMENT); + ini_set('display_errors', true); + error_reporting(E_ALL); +} else { + ini_set('display_errors', false); +} + + +/** + * Connect to database + */ +Db::connect( + 'mysql:host=' . config('database')['host'] . ';dbname=' . config('database')['db'] . ';charset=utf8', + config('database')['user'], + config('database')['pw'] +) || die('Error: Unable to connect to database'); +Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + +/** + * Include legacy code + */ require_once realpath(__DIR__ . '/../includes/sys_auth.php'); require_once realpath(__DIR__ . '/../includes/sys_form.php'); require_once realpath(__DIR__ . '/../includes/sys_log.php'); @@ -71,17 +126,6 @@ require_once realpath(__DIR__ . '/../includes/helper/email_helper.php'); require_once realpath(__DIR__ . '/../includes/mailer/shifts_mailer.php'); require_once realpath(__DIR__ . '/../includes/mailer/users_mailer.php'); -$config = []; -require_once realpath(__DIR__ . '/../config/config.default.php'); -if (file_exists(realpath(__DIR__ . '/../config/config.php'))) { - require_once realpath(__DIR__ . '/../config/config.php'); -} - -if ($maintenance_mode) { - echo file_get_contents(__DIR__ . '/../public/maintenance.html'); - die(); -} - require_once realpath(__DIR__ . '/../includes/pages/admin_active.php'); require_once realpath(__DIR__ . '/../includes/pages/admin_arrive.php'); require_once realpath(__DIR__ . '/../includes/pages/admin_free.php'); @@ -100,20 +144,10 @@ require_once realpath(__DIR__ . '/../includes/pages/user_questions.php'); require_once realpath(__DIR__ . '/../includes/pages/user_settings.php'); require_once realpath(__DIR__ . '/../includes/pages/user_shifts.php'); -$errorHandler = new ExceptionHandler( - ($environment == 'development' - ? ExceptionHandler::ENV_DEVELOPMENT - : ExceptionHandler::ENV_PRODUCTION - ) -); - -Db::connect( - 'mysql:host=' . $config['host'] . ';dbname=' . $config['db'] . ';charset=utf8', - $config['user'], - $config['pw'] -) || die('Error: Unable to connect to database'); -Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +/** + * Init application + */ session_start(); gettext_init(); -- cgit v1.2.3-70-g09d2