🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:19
This commit is contained in:
@@ -11,14 +11,13 @@ final class Application
|
||||
{
|
||||
private Container $container;
|
||||
private Router $router;
|
||||
public static ?array $config = null;
|
||||
|
||||
public function __construct(string $basePath)
|
||||
{
|
||||
// 1. Load Environment Variables (Point to the specific 'env' folder outside htdocs)
|
||||
// Path: /home/intaleqapp-musadaq/env/
|
||||
$envPath = dirname(dirname(dirname($basePath))) . '/env';
|
||||
|
||||
$dotenv = Dotenv::createImmutable($envPath);
|
||||
// 1. Load Environment Variables
|
||||
// In local dev, .env is in the project root. In production, it might be moved.
|
||||
$dotenv = Dotenv::createImmutable($basePath);
|
||||
$dotenv->load();
|
||||
|
||||
// 2. Set Timezone
|
||||
@@ -26,6 +25,10 @@ final class Application
|
||||
|
||||
// 3. Initialize Core Components
|
||||
$this->container = new Container();
|
||||
|
||||
// 4. Load Configurations
|
||||
$this->loadConfigs($basePath);
|
||||
|
||||
$this->router = new Router($this->container);
|
||||
|
||||
// Register core services in container
|
||||
@@ -33,6 +36,20 @@ final class Application
|
||||
$this->container->set(Router::class, $this->router);
|
||||
}
|
||||
|
||||
private function loadConfigs(string $basePath): void
|
||||
{
|
||||
$configPath = $basePath . '/config';
|
||||
$configs = [];
|
||||
|
||||
foreach (glob($configPath . '/*.php') as $file) {
|
||||
$key = basename($file, '.php');
|
||||
$configs[$key] = require $file;
|
||||
}
|
||||
|
||||
self::$config = $configs;
|
||||
$this->container->set('config', $configs);
|
||||
}
|
||||
|
||||
public function getRouter(): Router
|
||||
{
|
||||
return $this->router;
|
||||
@@ -40,6 +57,16 @@ final class Application
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
// 1. Security Headers
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('X-Frame-Options: DENY');
|
||||
header('X-XSS-Protection: 1; mode=block');
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains; preload');
|
||||
header('Referrer-Policy: strict-origin-when-cross-origin');
|
||||
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
|
||||
header('Content-Security-Policy: default-src \'self\'; script-src \'self\' cdn.tailwindcss.com unpkg.com; style-src \'self\' \'unsafe-inline\' fonts.googleapis.com; font-src fonts.gstatic.com');
|
||||
header_remove('X-Powered-By');
|
||||
|
||||
try {
|
||||
$request = new Request();
|
||||
$this->router->dispatch($request, $this->container);
|
||||
|
||||
Reference in New Issue
Block a user