<?php

session_start();

// SRC is defined as the path to the src/ directory from public/

define('CLASS_MAP', [
	'Database'  => '/database.php',
	'Router'    => '/router.php',
	'User'      => '/models/user.php',
	'Character' => '/models/character.php',
	'Wallet'    => '/models/wallet.php',
	'Session'   => '/models/session.php',
]);

require_once SRC . '/helpers.php';
require_once SRC . '/util/auth.php';
require_once SRC . '/util/components.php';
require_once SRC . '/util/enums.php';

require_once SRC . '/models/token.php';

spl_autoload_register(function (string $class) {
	if (array_key_exists($class, CLASS_MAP)) require_once SRC . CLASS_MAP[$class];
});

// Track the start time of the request
define('START_TIME', microtime(true));

/*
	Load env, set error reporting, etc.
*/
env_load(SRC . '/../.env');

if (env('debug') === 'true') {
	ini_set('display_errors', '1');
	ini_set('display_startup_errors', '1');
	error_reporting(E_ALL);
}

// Create an array in GLOBALS to hold database connections.
$GLOBALS['databases'] = [];

// Generate a new CSRF token. (if one doesn't exist, that is)
csrf();

// Run auth_check to see if we're logged in, since it populates the user data in SESSION
auth_check();
