-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
76 lines (64 loc) · 2.2 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
ini_set('session.gc_maxlifetime', 86400); // 24 hours
/**
* Bootstrap Script
*/
define('APPLICATION_PATH', dirname(__FILE__));
define('APPLICATION_LIBS', APPLICATION_PATH.'/libs');
define('APPLICATION_CONTROLLERS', APPLICATION_PATH.'/controllers');
define('APPLICATION_TEMPLATES', APPLICATION_PATH.'/templates');
define('APPLICATION_RESULTS', dirname(__FILE__).'/results');
define('CALIBRAZIONE', APPLICATION_PATH.'/calibrazione.txt');
define('TESTWS_COLORI_RIFERIMENTO', APPLICATION_PATH.'/colori_riferimento_sat.txt');
define('TESTL_COLORI_RIFERIMENTO', APPLICATION_PATH.'/colori_riferimento.txt');
//initialize session
session_start();
//controllo dei path
include_once APPLICATION_LIBS.'/Request.php';
$Request = new Request();
$Request->parseRequest();
//check status
include_once(APPLICATION_LIBS.'/TemplateManager.php');
$TemplateManager = TemplateManager::init(array(
'templateFolder' => APPLICATION_TEMPLATES,
'basePath' => '/'
));
//dispatch correct
$controller = 'default';
$action = 'index';
if($Request->getController()){
$controller = $Request->getController();
}
if($Request->getAction()){
$action = $Request->getAction();
}
//CHECK SESSION
if(!isset($_SESSION['sessionName']) &&
$controller != 'login'){
$controller = 'login';
$action = 'index';
} else if($_SESSION['sessionName'] == 'admin'){
define('DEBUG', true);
}
//GENERATE CONTROLLER
$controllerName = ucfirst($controller)."Controller";
if(file_exists(APPLICATION_CONTROLLERS."/".$controllerName.'.php')){
include_once APPLICATION_CONTROLLERS."/".$controllerName.'.php';
}
try{
if(class_exists($controllerName)){
$controller = new $controllerName($Request);
} else {
throw new Exception("Controller not found");
}
$actionName = $action."Action";
if(method_exists($controller, $actionName)){
echo $controller->$actionName();
} else {
throw new Exception("Action not found");
}
} catch (Exception $ex){
include_once APPLICATION_CONTROLLERS."/ErrorController.php";
$controller = new ErrorController($Request);
echo $controller->E404Action();
}