-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
52 lines (46 loc) · 1.5 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
<?php
use Kaida\MultiException\Errors;
use App\Exceptions\DbException;
use App\Exceptions\E404Exception;
use App\View;
use App\Logger;
use SebastianBergmann\Timer\Timer;
//use App\Mailer;
require_once __DIR__ . '/autoload.php';
session_start();
Timer::start();
$ctrlName = $_GET['ctrl'] ?? 'ArticleController';
$action = $_GET['action'] ?? 'showAllNews';
$class = '\App\Controllers\\' . $ctrlName;
try {
if (class_exists($class) && method_exists($class, $action)) {
/**@var \App\Controller $ctrl*/
$ctrl = new $class;
$ctrl->action($action);
} else {
throw new E404Exception('Ошибка 404 - не найдено');
}
} catch (DbException $error) {
$log = new Logger();
$log->critical('Ошибка в БД: ' . $error->getMessage(), [$error->getFile(), $error->getLine()]);
/*Mailer::getInstance()->sendEmail(
'Critical error!',
'This is the plain text body of the message.'
);*/
$view = new View();
$view->display(__DIR__ . '/template/error.php');
} catch (Errors $errors) {
$view = new View();
$view->errors = $errors->all();
$view->display(__DIR__ . '/template/errors.php');
} catch (E404Exception $error) {
$log = new Logger();
$log->notice($error->getMessage(), [$error->getFile(), $error->getLine()]);
$view = new View();
$view->error = $error->getMessage();
$view->display(__DIR__ . '/template/error404.php');
}
Timer::stop();
echo '<br>';
echo Timer::resourceUsage();