<?php
/**
 * This is the main file to be included on every page.
 * It will act as a front controller of our application.
 *   _____
 *  /     \
 * | () () |
 *  \  ^  /
 *   |||||
 *   |||||
 *
 * Tread carefully
 */

$php_version = '8';
if (version_compare(PHP_VERSION, $php_version, '<'))
{
    echo 'This app requires a minimum of PHP ' . $php_version . ' current being: ' . PHP_VERSION . "\n";
    die();
}
unset($php_version);

// PSR-4 like autoloader
spl_autoload_register(
    function ($class_name) {
        $path = __DIR__ . '/lib/' . str_replace('\\', '/', $class_name) . '.php';
        require $path;
    }
);

use App\Core\ {
    ErrorHandler,
    Config,
    Database,
    Session,
    User,
    App,
    AccessControl
};

new ErrorHandler();

$config   = (new Config(__DIR__ . '/config.php'))->config;
$database = new Database($config['database']);
$session  = new Session();
$user     = new User($session, $database);
$app      = new App(__DIR__, $config, $database, $session, $user);

// we will use $app instead
unset($config, $database, $session, $user);

new AccessControl($app);

return $app;