-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
77 lines (50 loc) · 2.1 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
<?php
use libraries\Log;
session_start();
// Настройки администратора (0 - публичное размещение, 1 - отладка)
ini_set('display_errors', 0); // Отображение ошибок
error_reporting(E_ALL);
define('A_MODE', 0); // Режим администратора
define('C_MODE', 0); // Режим проверки
define('D_MODE', 0); // Режим диагностики
define('P_MODE', 1); // Использование плагинов
// Подключение технических функций администратора на время работ
if(A_MODE) require_once $_SERVER['DOCUMENT_ROOT'] . '/libraries/Admin.php';
// Автозагрузка классов
spl_autoload_register(function($class) {
$ds = DIRECTORY_SEPARATOR;
$path = $_SERVER['DOCUMENT_ROOT'] . $ds . str_replace('\\', $ds, $class) . '.php';
addClass($path);
});
// Загрузка класса
function addClass($path) {
if(D_MODE) {
try {
if(!file_exists($path)) throw new \Exception('отсутствует файл с классом: ' . $path);
} catch(\Exception $e) {
logError($e, 0);
}
}
require $path;
}
// Логирование ошибок
function logError($catch, $type, $show = true) {
$log = new Log;
if(gettype($type) != 'integer') {
$method = 'log' . $type . 'Error';
$type = 2;
} else $method = 'logErrors';
$log->$method($catch, $type);
redirect($show);
}
// Рекдирект
function redirect($url) {
if($url === true) header('location: /404.php');
elseif($url == 'insert') echo "window.location.href = '/404.php';";
elseif($url == 'script') echo "<script>window.location.href = '/404.php';</script>";
else header('location: /' . $url);
if($url != 'insert') exit;
}
// Запуск маршрутизатора
$routeController = '\application\core\RouteController';
new $routeController;