-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
92 lines (64 loc) · 2.04 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once __DIR__.'/bootstrap/Bootstrap.php';
require_once __DIR__.'/routes.php';
/**
* Função auxiliar para tratar warnings e notices como exceptions.
*/
function custom_error_handler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
return;
}
switch ($errno) {
case E_USER_ERROR:
echo "<b>ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;
case E_USER_WARNING:
throw new Exception("<b>WARNING</b> [$errno] $errstr<br />\n");
break;
case E_USER_NOTICE:
throw new Exception("<b>NOTICE</b> [$errno] $errstr<br />\n");
break;
default:
throw new Exception("Unknown error type: [$errno] $errstr<br />\n");
break;
}
return true;
}
// Define o handler customizado para tratamento de warnings e notices
set_error_handler("custom_error_handler");
/**
* =============================================================================
* == ROTEAMENTO DE URL'S ==
* =============================================================================
*/
$url = explode('/', $_GET['url']);;
$ctr = NULL;
if (isset($url) && isset($routes)) {
$ctr = $routes[$url[0]];
} else {
die("Erro! Url nao definida.");
}
try {
require_once __DIR__ . '/controller/' . $ctr . '.php';
$controller = new $ctr();
if (sizeof($url) == 3) {
// GET: controller/action/id
$controller->$url[1]($url[2]);
} else {
if (isset($url[1])) {
// GET: controller/action
$controller->$url[1]();
} else {
// GET: controller
$controller->Index();
}
}
} catch (Exception $ex) {
$index = new HomeController();
$index->Index();
}