<?php

use CodeIgniter\Boot;
use Config\Paths;

if (PHP_SAPI === 'cli-server') {
    $urlPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
    if (is_string($urlPath) && $urlPath !== '/' && is_file(__DIR__ . $urlPath)) {
        return false;
    }
}

$minPhpVersion = '8.2';
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
    $message = sprintf(
        'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
        $minPhpVersion,
        PHP_VERSION,
    );

    header('HTTP/1.1 503 Service Unavailable.', true, 503);
    echo $message;

    exit(1);
}

$host = $_SERVER['HTTP_HOST'] ?? '';
$environment = in_array($host, ['localhost', '192.168.10.74', '192.168.30.184'], true)
    ? 'development'
    : 'production';
$_ENV['CI_ENVIRONMENT']    = $environment;
$_SERVER['CI_ENVIRONMENT'] = $environment;
putenv('CI_ENVIRONMENT=' . $environment);

define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

if (getcwd() . DIRECTORY_SEPARATOR !== FCPATH) {
    chdir(FCPATH);
}

require FCPATH . 'app/Config/Paths.php';

$paths = new Paths();

require $paths->systemDirectory . '/Boot.php';

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