Files
domnitor/core/Application.php

51 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2025-10-08 14:23:07 +03:00
<?php
namespace Core;
use App\Services\ErrorHandler;
2025-10-08 14:23:07 +03:00
class Application
{
public static Router $router;
public static Database $db;
private ErrorHandler $errorHandler;
2025-10-08 14:23:07 +03:00
public function __construct()
{
// Configure error reporting based on environment
$this->configureErrorReporting();
2025-10-08 14:23:07 +03:00
self::$router = new Router();
self::$db = new Database();
// Initialize error handler
$this->errorHandler = new ErrorHandler();
2025-10-08 14:23:07 +03:00
}
private function configureErrorReporting()
{
$env = $_ENV['APP_ENV'] ?? 'development';
if ($env === 'production') {
// In production, suppress deprecation warnings to prevent header issues
2025-10-29 12:49:40 +02:00
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', '0');
} else {
// In development, show all errors including deprecations
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
}
2025-10-08 14:23:07 +03:00
public function run()
{
try {
self::$router->resolve();
} catch (\Throwable $e) {
// Use centralized error handler
$this->errorHandler->handleException($e);
2025-10-08 14:23:07 +03:00
}
}
}