2022-01-15 10:26:02 +00:00
|
|
|
<?php
|
2022-03-02 06:15:12 +00:00
|
|
|
/**
|
|
|
|
* This is the main file to be included on every page.
|
|
|
|
* It will act as a front controller of our application.
|
|
|
|
* _____
|
|
|
|
* / \
|
|
|
|
* | () () |
|
|
|
|
* \ ^ /
|
|
|
|
* |||||
|
|
|
|
* |||||
|
|
|
|
*
|
|
|
|
* Tread carefully
|
|
|
|
*/
|
|
|
|
|
|
|
|
// disable type coercion
|
2022-01-23 21:56:36 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// PSR-4 like autoloader
|
|
|
|
spl_autoload_register(
|
|
|
|
function ($className) {
|
|
|
|
$path = __DIR__ . '/lib/' . str_replace('\\', '/', $className) . '.php';
|
|
|
|
require $path;
|
|
|
|
}
|
|
|
|
);
|
2022-01-17 10:25:34 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// imports
|
|
|
|
use App\Core\ {
|
|
|
|
ErrorHandler,
|
|
|
|
Config,
|
|
|
|
Database,
|
|
|
|
Session,
|
|
|
|
User,
|
|
|
|
App,
|
|
|
|
AccessControl
|
|
|
|
};
|
2022-01-30 21:11:38 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// displays a custom page on error or exception
|
|
|
|
new ErrorHandler();
|
2022-01-27 22:17:43 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// grab configuration file
|
|
|
|
$config = (new Config(__DIR__ . '/config.php'))->config;
|
2022-01-27 22:17:43 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// start database connection
|
2022-01-21 20:32:21 +00:00
|
|
|
$database = new Database($config['database']);
|
2022-02-06 02:35:20 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// session wrapper
|
|
|
|
$session = new Session();
|
2022-02-06 02:35:20 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// handles current user session
|
|
|
|
$user = new User($session, $database);
|
2022-01-21 20:32:21 +00:00
|
|
|
|
2022-01-30 21:11:38 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
$app = new App(__DIR__, $config, $database, $session, $user);
|
2022-01-21 20:32:21 +00:00
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
// 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']);
|
2022-01-21 20:32:21 +00:00
|
|
|
|
|
|
|
return $app;
|