Initial commit
This commit is contained in:
48
backend/app/bootstrap.php
Normal file
48
backend/app/bootstrap.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Nabeh Application Bootstrap Loader
|
||||
* Handles PSR-4 Autoloading, security settings, and error handling.
|
||||
*/
|
||||
|
||||
// Define absolute path to application root
|
||||
define('APP_ROOT', dirname(__DIR__));
|
||||
|
||||
// 1. PSR-4 Autoloader
|
||||
spl_autoload_register(function ($class) {
|
||||
// Namespace prefix
|
||||
$prefix = 'App\\';
|
||||
// Directory mapping for the prefix
|
||||
$base_dir = APP_ROOT . '/app/';
|
||||
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
return; // Move to next registered autoloader
|
||||
}
|
||||
|
||||
$relative_class = substr($class, $len);
|
||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Load Environment Variables
|
||||
try {
|
||||
\App\Core\Env::load(APP_ROOT . '/.env');
|
||||
} catch (\Exception $e) {
|
||||
// In production, log error; in development, print it
|
||||
error_log('Env Load Error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// 3. Configure Error Reporting based on environment
|
||||
$isDebug = filter_var(getenv('APP_DEBUG') ?: true, FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
if ($isDebug) {
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
} else {
|
||||
ini_set('display_errors', '0');
|
||||
error_reporting(0);
|
||||
}
|
||||
Reference in New Issue
Block a user