diff options
Diffstat (limited to 'src/app/bootstrap.php')
| -rw-r--r-- | src/app/bootstrap.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/app/bootstrap.php b/src/app/bootstrap.php new file mode 100644 index 0000000..835615b --- /dev/null +++ b/src/app/bootstrap.php @@ -0,0 +1,42 @@ +<?php + +declare(strict_types=1); +// Application bootstrap: loads .env, registers the autoloader, and configures error reporting. + +session_start(); + +// Load .env +$envFile = dirname(__DIR__, 2) . '/.env'; +if (file_exists($envFile)) { + $lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + foreach ($lines as $line) { + if (str_starts_with(trim($line), '#')) { + continue; + } + $parts = explode('=', $line, 2); + if (count($parts) === 2) { + $key = trim($parts[0]); + $value = trim($parts[1]); + $_ENV[$key] = $value; + putenv("$key=$value"); + } + } +} + +// Autoloader +spl_autoload_register(function (string $class): void { + $prefix = 'App\\'; + if (!str_starts_with($class, $prefix)) { + return; + } + $relative = substr($class, strlen($prefix)); + $file = __DIR__ . '/' . str_replace('\\', '/', $relative) . '.php'; + if (file_exists($file)) { + require $file; + } +}); + +// Error reporting +error_reporting(E_ALL); +ini_set('display_errors', '0'); +ini_set('log_errors', '1'); |
