<?php

declare(strict_types=1);

use App\Core\Application;
use App\Core\Autoloader;

/*
 * public/index.php — the ONLY PHP file the web server ever executes
 * directly. Every request, page or API call alike, funnels through
 * here and out through App\Core\Router. Nothing else in /public
 * should ever contain application logic.
 */

$basePath = dirname(__DIR__);

// Prefer Composer's autoloader once `composer install` has been run
// (it also autoloads PHPMailer and any other vendor package). Fall
// back to our own minimal PSR-4 autoloader for App\* so the app still
// boots on a fresh checkout before Composer has ever been run.
if (is_file($basePath . '/vendor/autoload.php')) {
    require $basePath . '/vendor/autoload.php';
} else {
    require $basePath . '/app/Core/Autoloader.php';
    Autoloader::register($basePath);
}

require $basePath . '/app/Helpers/functions.php';

Application::boot($basePath);
Application::handle();
