59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Application Bootstrap Initialization
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
// 1. Basic Constants
|
|
define('ROOT_PATH', dirname(__DIR__, 2));
|
|
define('APP_PATH', ROOT_PATH . '/app');
|
|
define('STORAGE_PATH', ROOT_PATH . '/storage');
|
|
|
|
// 2. Load Environment Loader & Helpers FIRST
|
|
require_once APP_PATH . '/bootstrap/env.php';
|
|
require_once APP_PATH . '/helpers/helpers.php';
|
|
|
|
// 3. Error Reporting (Secure for production - Now we can use env())
|
|
if (env('APP_DEBUG', 'false') === 'true') {
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', '1');
|
|
} else {
|
|
error_reporting(0);
|
|
ini_set('display_errors', '0');
|
|
}
|
|
|
|
// 4. Security Headers
|
|
header("X-Content-Type-Options: nosniff");
|
|
header("X-Frame-Options: DENY");
|
|
header("X-XSS-Protection: 1; mode=block");
|
|
header("Referrer-Policy: strict-origin-when-cross-origin");
|
|
|
|
// 5. Intelligent Autoloader (Case-Insensitive for directories)
|
|
spl_autoload_register(function ($class) {
|
|
$prefix = 'App\\';
|
|
$base_dir = APP_PATH . '/';
|
|
|
|
$len = strlen($prefix);
|
|
if (strncmp($prefix, $class, $len) !== 0) return;
|
|
|
|
$relative_class = substr($class, $len);
|
|
|
|
// Normalize path to lowercase for directories, keep filename case
|
|
$parts = explode('\\', $relative_class);
|
|
$filename = array_pop($parts) . '.php';
|
|
$dir = strtolower(implode('/', $parts));
|
|
|
|
$file = $base_dir . ($dir ? $dir . '/' : '') . $filename;
|
|
|
|
if (file_exists($file)) {
|
|
require $file;
|
|
}
|
|
});
|
|
|
|
// 6. Response Utility
|
|
require_once APP_PATH . '/bootstrap/response.php';
|
|
|
|
// 7. Global Auth Helper
|
|
require_once APP_PATH . '/bootstrap/auth.php';
|