66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.3 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
 | |
|  */
 | |
| 
 | |
| // disable type coercion
 | |
| declare(strict_types=1);
 | |
| 
 | |
| // PSR-4 like autoloader
 | |
| spl_autoload_register(
 | |
|     function ($className) {
 | |
|         $path = __DIR__ . '/lib/' . str_replace('\\', '/', $className) . '.php';
 | |
|         require $path;
 | |
|     }
 | |
| );
 | |
| 
 | |
| // imports
 | |
| use App\Core\ {
 | |
|     ErrorHandler,
 | |
|     Config,
 | |
|     Database,
 | |
|     Session,
 | |
|     User,
 | |
|     App,
 | |
|     AccessControl
 | |
| };
 | |
| 
 | |
| // displays a custom page on error or exception 
 | |
| new ErrorHandler();
 | |
| 
 | |
| // grab configuration file
 | |
| $config = (new Config(__DIR__ . '/config.php'))->config;
 | |
| 
 | |
| // start database connection
 | |
| $database = new Database($config['database']);
 | |
| 
 | |
| // session wrapper
 | |
| $session = new Session();
 | |
| 
 | |
| // handles current user 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; |