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

62 lines
1.1 KiB
PHP
Raw Normal View History

2022-01-15 10:26:02 +00:00
<?php
/*
This is the main file to be included on every page.
It will act as a front controller of our application.
2022-01-16 16:12:04 +00:00
_____
/ \
| () () |
\ ^ /
|||||
|||||
Tread carefully
2022-01-15 10:26:02 +00:00
*/
2022-01-23 21:56:36 +00:00
// Disable type coercion
declare(strict_types=1);
2022-01-17 10:25:34 +00:00
// Autoloader
2022-01-15 10:26:02 +00:00
spl_autoload_register(function ($class_name) {
require __DIR__ . '/core/' . $class_name . '.php';
});
2022-01-17 10:25:34 +00:00
2022-01-30 21:11:38 +00:00
/* === App Setup === */
2022-02-06 02:35:20 +00:00
// Displays a custom page on error or exception
2022-01-27 22:17:43 +00:00
new ErrorHandler;
2022-02-06 02:35:20 +00:00
// Grab configuration file
2022-01-24 07:38:51 +00:00
$config = (
new Config(__DIR__ . '/config.php')
)->config;
2022-01-27 22:17:43 +00:00
2022-02-06 02:35:20 +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
// Session wrapper
2022-01-21 20:32:21 +00:00
$session = new Session;
2022-02-06 02:35:20 +00:00
// Handles current user session
2022-02-02 11:47:06 +00:00
$user = new User($session, $database);
2022-01-21 20:32:21 +00:00
2022-02-27 08:16:03 +00:00
// THIS IS IMPORTANT!!
// Without it, everyone will have access to any page without having to be logged in.
2022-02-06 02:35:20 +00:00
// Decides if the user is allowed to view current page
2022-02-07 09:28:28 +00:00
new AccessControl($user, $config['root_url']);
2022-01-30 21:11:38 +00:00
2022-01-21 20:32:21 +00:00
$app = new App(
$config,
$database,
2022-01-23 21:56:36 +00:00
$session,
$user
2022-01-21 20:32:21 +00:00
);
2022-01-23 21:56:36 +00:00
// We will use $app instead
2022-01-21 20:32:21 +00:00
unset(
$config,
$database,
2022-01-23 21:56:36 +00:00
$session,
$user
2022-01-21 20:32:21 +00:00
);
return $app;