<?php

/**
 * CodeIgniter 4 — Front Controller
 * Compatible with CI4 4.4+ (uses Boot.php, not bootstrap.php)
 */

// Check minimum PHP version
$minPhpVersion = '8.1';
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
    header('HTTP/1.1 503 Service Unavailable.', true, 503);
    echo sprintf(
        'Your PHP version must be %s or higher. Current: %s',
        $minPhpVersion,
        PHP_VERSION
    );
    exit(1);
}

// Path to this file (public/)
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

// Ensure CWD is public/
if (getcwd() . DIRECTORY_SEPARATOR !== FCPATH) {
    chdir(FCPATH);
}

// Load Paths config — CI4 4.4+ instantiates the class directly
require FCPATH . '../app/Config/Paths.php';
$paths = new Config\Paths();

// Load Composer autoloader BEFORE bootWeb so all CI4 classes
// (e.g. CodeIgniter\Exceptions\*) are available during DotEnv parsing.
// FCPATH = public/, so '../vendor/autoload.php' = project root vendor/
$composerAutoload = FCPATH . '../vendor/autoload.php';
if (is_file($composerAutoload)) {
    require_once $composerAutoload;
}

// Boot the framework using Boot.php (replaces old bootstrap.php)
require $paths->systemDirectory . '/Boot.php';

exit(CodeIgniter\Boot::bootWeb($paths));
