/
Dispatcher.php
75 lines (73 loc) · 2.28 KB
/
Dispatcher.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
<?php
namespace Bootstrap;
use \Exception,
\RuntimeException,
\Exceptions\ForbiddenException,
\Exceptions\NotFoundException,
\Framework\Core\Config,
\Framework\Common\Log,
\Framework\Core\Template,
\Framework\Common\SwiftMailer;
class Dispatcher
{
public function __construct()
{
try {
Bootstrap::boot();
}
catch (RuntimeException $e)
{
/**
* Simple runtime errors handler
*/
if (Config::get('framework', 'phpdebug')) {
echo "RuntimeException: " . $e->getMessage() . "<br><pre>" . $e->getTraceAsString();
} else {
Log::writeException($e);
echo "<b>Notice:</b> critical system error";
if ($adminEmail = Config::get('application', 'admin_email'))
{
$point = md5(date('Y-m-d H')) . '.log';
if (!file_exists('app/logs/' . $point))
{
Log::write('Runtime exception sended for admin', $point);
SwiftMailer::send(SwiftMailer::createMessage(
"Runtime exception [{$_SERVER['HTTP_HOST']}]",
$adminEmail, $e->getMessage()
));
}
}
}
}
catch (ForbiddenException $e)
{
/**
* Simple 403 error page
*/
header('HTTP/1.0 403 Forbidden');
$template = new Template();
echo $template->render('403', 'native');
}
catch (NotFoundException $e)
{
/**
* Simple 404 error page
*/
header('HTTP/1.0 404 Not Found');
$template = new Template();
echo $template->render('404', 'native');
}
catch (Exception $e)
{
/**
* Simple other exceptions handler
*/
if (Config::get('framework', 'phpdebug')) {
echo "Exception: " . $e->getMessage() . "<br><pre>" . $e->getTraceAsString();
} else {
Log::writeException($e);
echo "<b>Notice:</b> system error";
}
}
}
}