<?php

/**
 * Inveetaire — Front Controller
 *
 * This is the SINGLE ENTRY POINT for ALL HTTP requests to the application.
 * Apache rewrites every request to this file (configured in INIT-004).
 *
 * Direct browser access to any file outside public/ must return 403 Forbidden.
 * That restriction is enforced by Apache .htaccess rules (INIT-004).
 *
 * Execution sequence:
 *   1. Define ROOT_PATH constant
 *   2. Require and register the Autoloader
 *   3. Create Application and call run()
 *
 * @package  Inveetaire
 * @ref      DBP v1.0 Ch.5, SAD v1.1 Ch.4, INIT-003
 */

// ─────────────────────────────────────────────────────────────────────────────
// STEP 1 — Define ROOT_PATH
//
// Absolute filesystem path to the project root (one level above public/).
// All other paths in the application derive from this constant.
// Do NOT include a trailing slash.
// ─────────────────────────────────────────────────────────────────────────────
define('ROOT_PATH', dirname(__DIR__));

// ─────────────────────────────────────────────────────────────────────────────
// STEP 2 — Require and Register the Autoloader
//
// The Autoloader cannot load itself — it must be required manually.
// After register(), all App\ classes resolve automatically.
// ─────────────────────────────────────────────────────────────────────────────
require_once ROOT_PATH . '/app/core/Autoloader.php';
\App\Core\Autoloader::register();

if (file_exists(ROOT_PATH . '/vendor/autoload.php')) {
    require_once ROOT_PATH . '/vendor/autoload.php';
}

// ─────────────────────────────────────────────────────────────────────────────
// STEP 3 — Create and Run the Application
//
// Application::__construct()  → creates Bootstrap
// Application::run()          → Bootstrap::init() → handleRequest() stub
//
// Router dispatch (INIT-007) and Session (INIT-010) will extend run().
// ─────────────────────────────────────────────────────────────────────────────
$app = new \App\Core\Application();
$app->run();
