-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
51 lines (43 loc) · 1.39 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
if (isset($_SERVER['IS_DEVELOPER_MODE'])) {
ini_set('display_errors', 1);
error_reporting(E_ALL);
} else {
ini_set('display_errors', 0);
}
if (!isset($_SESSION)) {
session_start();
}
date_default_timezone_set('Europe/Paris');
define('ROOT', str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']));
require_once(ROOT . 'core/conf.php');
require_once(ROOT . 'core/parameters.php');
require_once(ROOT . 'core/Auth.php');
require_once(ROOT . 'core/Routing.php');
require_once(ROOT . 'core/BaseModel.php');
require_once(ROOT . 'core/BaseController.php');
require_once(ROOT . 'controllers/CRUD.php');
$routing = new Routing();
$route = $routing->parseUri();
$controllerName = ucfirst($route['controller']) . 'Controller';
$controllerFile = 'controllers/' . $controllerName . '.php';
if (file_exists($controllerFile)) {
require_once($controllerFile);
} else {
header("HTTP/1.0 404 Not Found");
exit('Oops an error has occured! Please try again later.');
}
$auth = new Auth();
if ($auth->authenticate()) {
$controller = new $controllerName;
$action = $route['action'] . 'Action';
if (method_exists($controller, $action)) {
$routing->call_user_func_named($controller, $action, $route['args']);
} else {
header("HTTP/1.0 404 Not Found");
exit('Oops an error has occured! Please try again later.');
}
} else {
header("HTTP/1.0 403 Forbidden");
exit('You are not allowed to access this ressource.');
}