This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/inc.php
2022-03-07 07:13:17 +01:00

56 lines
1.1 KiB
PHP

<?php
/**
* This is the main file to be included on every page.
* It will act as a front controller of our application.
* _____
* / \
* | () () |
* \ ^ /
* |||||
* |||||
*
* Tread carefully
*/
// PSR-4 like autoloader
spl_autoload_register(
function ($className) {
$path = __DIR__ . '/lib/' . str_replace('\\', '/', $className) . '.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);
/**
* This is important!
* Without it, everyone will have access to any page without having to be logged in.
*
* Decides if the user is allowed to view current page.
*/
new AccessControl($app->user, $app->config['root_url']);
return $app;