<?php

declare(strict_types=1);

/*
 * Front controller. Every request that is not a file under public/ arrives here.
 */

use App\Support\Application;
use App\Support\Http\Request;

$basePath = dirname(__DIR__);

// Maintenance mode is a flag file, checked before anything else is loaded (guide, Section 37).
if (is_file($basePath . '/storage/maintenance.flag')) {
    http_response_code(503);
    header('Retry-After: 300');
    header('Content-Type: text/html; charset=UTF-8');
    readfile($basePath . '/resources/views/maintenance.html');

    return;
}

require $basePath . '/vendor/autoload.php';

Application::registerErrorHandling();
Application::boot($basePath)->handle(Request::fromGlobals())->send();
