51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
|
$dotenv->load();
|
|
|
|
// Normalize HTTPS detection behind proxies and based on HOST env
|
|
// If behind a reverse proxy, X-Forwarded-Proto may indicate HTTPS
|
|
$forwardedProto = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) : null;
|
|
$hostEnv = $_ENV['HOST'] ?? null;
|
|
|
|
// If HOST env is set and starts with https, treat as secure
|
|
if (is_string($hostEnv) && stripos($hostEnv, 'https://') === 0) {
|
|
$_SERVER['HTTPS'] = 'on';
|
|
}
|
|
|
|
// If proxy indicates https, treat connection as secure
|
|
if ($forwardedProto === 'https') {
|
|
$_SERVER['HTTPS'] = 'on';
|
|
}
|
|
|
|
// PSR-4 Autoloader for Services and Controllers
|
|
spl_autoload_register(function ($class) {
|
|
// Remove leading namespace separator
|
|
$class = ltrim($class, '\\');
|
|
|
|
// Define namespace to directory mapping
|
|
$prefixes = [
|
|
'Services\\' => __DIR__ . '/src/Services/',
|
|
'Controllers\\' => __DIR__ . '/src/Controllers/',
|
|
'Middleware\\' => __DIR__ . '/src/Middleware/',
|
|
];
|
|
|
|
foreach ($prefixes as $prefix => $baseDir) {
|
|
if (strpos($class, $prefix) === 0) {
|
|
// Remove the prefix from the class
|
|
$relativeClass = substr($class, strlen($prefix));
|
|
|
|
// Build the file path
|
|
$file = $baseDir . str_replace('\\', DIRECTORY_SEPARATOR, $relativeClass) . '.php';
|
|
|
|
if (file_exists($file)) {
|
|
require_once $file;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
});
|