Files
cmasa/app/config/bootstrap.php
T
2026-10-29 13:34:31 +07:00

84 lines
2.4 KiB
PHP

<?php
/*******************************************************************
Desc. : Proses Utama Aplikasi
Created By : Siau Pheng ([email protected]).
Created Date : November 23rd, 2019.
Last Modified : September 13th, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
$ds = DIRECTORY_SEPARATOR;
$projectRoot = dirname(__DIR__, 2);
require $projectRoot . $ds . 'vendor' . $ds . 'autoload.php';
use App\Utils\Config;
use App\Utils\Env;
/* Loading configuration from .env */
Env::load($projectRoot . $ds . '.env');
$configPath = __DIR__ . $ds . 'config.php';
if (file_exists($configPath) === false) {
Flight::halt(500, 'Ada kendala dengan Konfigurasi Aplikasi, hubungi Developer.');
}
/* App Main Configuration */
$fileConfig = require $configPath;
/* Merge from .env and config */
$merged = Config::mergeEnv($fileConfig, $_ENV);
$config = new Config($merged);
// Setup timezone from config
$timezone = (string) $config->get('app.timezone', 'UTC');
if (!empty($timezone)) date_default_timezone_set($timezone);
// Character encoding
if (function_exists('mb_internal_encoding') === true) {
mb_internal_encoding('UTF-8');
}
// Default Locale Change as needed or feel free to remove.
if (function_exists('setlocale') === true) {
setlocale(LC_ALL, 'en_US.UTF-8');
}
// Error reporting config
if ($config->env() === 'production') {
error_reporting(E_ALL & ~E_DEPRECATED);
} else {
error_reporting(E_ALL);
}
/* FlightPHP App Instance */
$app = Flight::app();
$app->set('app.project_root', $projectRoot);
$app->set('flight.base_url', $config->baseUrl());
$app->set('flight.case_sensitive', false);
$app->set('flight.log_errors', true);
$app->set('flight.handle_errors', $config->isDebug() === false);
$app->set('flight.views.path', __DIR__ . $ds . '..' . $ds . 'views');
$app->set('flight.views.extension', '.twig');
$app->set('flight.content_length', false);
$app->set('csp_nonce', bin2hex(random_bytes(16)));
if (!defined('PROJECT_ROOT')) define('PROJECT_ROOT', $projectRoot . '/');
if (!defined('PROJECT_BASE')) define('PROJECT_BASE', $config->baseUrl() . '/');
/* Loading Services */
require(__DIR__ . $ds . 'services.php');
/* Loading App Configuration */
require(__DIR__ . $ds . 'app.php');
/* Loading App Route Configuration */
require(__DIR__ . $ds . 'routes.php');
/* Start App */
$app->start();