2025-10-08 14:23:07 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Core;
|
|
|
|
|
|
2025-10-10 14:01:19 +03:00
|
|
|
use App\Services\ErrorHandler;
|
|
|
|
|
|
2025-10-08 14:23:07 +03:00
|
|
|
class Application
|
|
|
|
|
{
|
|
|
|
|
public static Router $router;
|
|
|
|
|
public static Database $db;
|
2025-10-10 14:01:19 +03:00
|
|
|
private ErrorHandler $errorHandler;
|
2025-10-08 14:23:07 +03:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2025-10-29 12:45:01 +02:00
|
|
|
// Configure error reporting based on environment
|
|
|
|
|
$this->configureErrorReporting();
|
|
|
|
|
|
2025-10-08 14:23:07 +03:00
|
|
|
self::$router = new Router();
|
|
|
|
|
self::$db = new Database();
|
2025-10-10 14:01:19 +03:00
|
|
|
|
|
|
|
|
// Initialize error handler
|
|
|
|
|
$this->errorHandler = new ErrorHandler();
|
2025-10-08 14:23:07 +03:00
|
|
|
}
|
2025-10-29 12:45:01 +02: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);
|
2025-10-29 12:45:01 +02:00
|
|
|
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();
|
2025-10-10 14:01:19 +03:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
// Use centralized error handler
|
|
|
|
|
$this->errorHandler->handleException($e);
|
2025-10-08 14:23:07 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|