DLight\Application\App

Mô tả: lõi khởi động ứng dụng. Nạp .env (TinyEnv), cấu hình môi trường, timezone, error handling, kiểm tra health, bật session và chạy Router. Có 2 entrypoint: webCLI/DLI.

Namespace / đăng ký

  • Namespace: DLight\Application
  • Autoload: PSR-4 (DLight\src/)
  • File: src/Application/App.php

Public API (dùng bên ngoài)

  • App::environment(): string
  • App::isDebug(): bool
  • App::isProduction(): bool
  • App::isRunningFromPhar(): bool
  • App::isRunningFromDocker(): bool
  • App::setMaintenanceMode(bool $noEnv = false): void
  • $app->setUpWebRoutes(string $path): self
  • $app->setUpApiRoutes(string $path): self
  • $app->setUpDliRoutes(string $path): self
  • $app->setSecurityHeaders(): self
  • $app->bootWeb(): void
  • $app->bootDli(array $argv): void

Cách dùng

Boot web (thường đặt trong public/index.php hoặc file entry tương đương):

use DLight\Application\App;

define('ROOT_DIR', __DIR__ . '/../');
define('INDEX_DIR', __DIR__ . '/../public/');

(new App())
  ->setUpWebRoutes(ROOT_DIR . 'app/Router/web.php')
  ->setUpApiRoutes(ROOT_DIR . 'app/Router/api.php')
  ->bootWeb();

Boot CLI/DLI (ví dụ file dlight hoặc bin/console):

use DLight\Application\App;

define('ROOT_DIR', __DIR__ . '/../');

(new App())
  ->setUpDliRoutes(ROOT_DIR . 'app/Router/command/command.php')
  ->bootDli($argv);

Ghi chú cấu hình (env)

  • Môi trường: APP_ENVIRONMENT (local/development/staging/production)
  • Debug: APP_DEBUG (tự tắt khi production)
  • Timezone: APP_TIMEZONE
  • Maintenance: MAINTENANCE_MODE, MAINTENANCE_START_TIME, MAINTENANCE_END_TIME