🚀 مُصادَق: الإطلاق الأولي للنظام المتكامل
This commit is contained in:
58
app/Core/Application.php
Normal file
58
app/Core/Application.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use App\Core\{Request, Response, Router, Container};
|
||||
|
||||
final class Application
|
||||
{
|
||||
private Container $container;
|
||||
private Router $router;
|
||||
|
||||
public function __construct(string $basePath)
|
||||
{
|
||||
// 1. Load Environment Variables
|
||||
$dotenv = Dotenv::createImmutable($basePath);
|
||||
$dotenv->load();
|
||||
|
||||
// 2. Set Timezone
|
||||
date_default_timezone_set($_ENV['APP_TIMEZONE'] ?? 'Asia/Amman');
|
||||
|
||||
// 3. Initialize Core Components
|
||||
$this->container = new Container();
|
||||
$this->router = new Router($this->container);
|
||||
|
||||
// Register core services in container
|
||||
$this->container->set(Container::class, $this->container);
|
||||
$this->container->set(Router::class, $this->router);
|
||||
}
|
||||
|
||||
public function getRouter(): Router
|
||||
{
|
||||
return $this->router;
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
try {
|
||||
$request = new Request();
|
||||
$this->router->dispatch($request, $this->container);
|
||||
} catch (\Throwable $e) {
|
||||
// Global Exception Handler
|
||||
Response::error(
|
||||
'حدث خطأ غير متوقع في النظام',
|
||||
'INTERNAL_SERVER_ERROR',
|
||||
500,
|
||||
$_ENV['APP_ENV'] === 'development' ? [
|
||||
'message' => $e->getMessage(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
] : null
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user