forked from easterism/core2
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbootstrap.php
More file actions
150 lines (123 loc) · 4.58 KB
/
Copy pathbootstrap.php
File metadata and controls
150 lines (123 loc) · 4.58 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
use Core2\I18n;
use Core2\Registry;
// Определяем DOCUMENT_ROOT (для прямых вызовов, например cron)
define("DOC_ROOT", realpath(__DIR__ . '/..') . DIRECTORY_SEPARATOR);
define("DOC_PATH", substr(DOC_ROOT, strlen(rtrim($_SERVER['DOCUMENT_ROOT'], '/'))) ?: '/');
$autoload = __DIR__ . "/vendor/autoload.php";
if ( ! file_exists($autoload)) {
throw new \Exception("Composer autoload is missing.", 500);
}
require_once $autoload;
require_once "inc/classes/Error.php";
if ( ! empty($_SERVER['REQUEST_URI'])) {
$request_ext = explode(".", basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
if ( ! empty($request_ext[1]) && in_array($request_ext[1], ['txt', 'js', 'css', 'env'])) {
throw new \Exception("File not found", 404);
}
}
require_once "inc/classes/Log.php";
require_once "inc/classes/Theme.php";
require_once "inc/classes/Registry.php";
require_once "inc/classes/Config.php";
require_once "inc/classes/Router.php";
require_once 'inc/classes/I18n.php';
require_once 'inc/classes/Common.php';
require_once 'inc/classes/Acl.php';
require_once 'inc/classes/SSE.php';
$conf_file = DOC_ROOT . "conf.ini";
if ( ! file_exists($conf_file)) {
throw new \Exception("conf.ini is missing.", 500);
}
$config_origin = [
'system' => ['name' => 'CORE2'],
'include_path' => '',
'temp' => getenv('TMP'),
'debug' => ['on' => false],
'session' => [
'cookie_httponly' => true,
'use_only_cookies' => true,
],
'database' => [
'adapter' => 'Pdo_Mysql',
'params' => [
'charset' => 'utf8',
'driver_options' => [
\PDO::ATTR_TIMEOUT => 5,
// \PDO::ATTR_PERSISTENT => true,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
],
'options' => [
'caseFolding' => false,
'autoQuoteIdentifiers' => true,
'allowSerialization' => true,
'autoReconnectOnUnserialize' => true,
],
],
'isDefaultTableAdapter' => true,
'profiler' => [
'enabled' => false,
'class' => 'Zend_Db_Profiler_Firebug',
],
],
];
// определяем путь к темповой папке
if (empty($config_origin['temp'])) {
$config_origin['temp'] = sys_get_temp_dir();
}
//обрабатываем общий конфиг
try {
$section = ! empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'production';
$conf = new Core2\Config($config_origin);
$system_config = $conf->getData()->merge($conf->readIni($conf_file, $section));
$conf_d = __DIR__ . "/conf.ext.ini";
if (file_exists($conf_d)) {
$system_config->merge($conf->readIni($conf_d, $section));
}
if (empty($_SERVER['HTTPS'])) {
if (isset($system_config->system) && ! empty($system_config->system->https)) {
header('Location: https://' . $_SERVER['SERVER_NAME']);
return;
}
}
$tz = $system_config->system->timezone;
if ( ! empty($tz)) {
date_default_timezone_set($tz);
}
if ( ! $system_config) {
throw new Exception("Unable to load configuration.");
}
} catch (Exception $e) {
throw new \Exception($e->getMessage(), 500);
}
// отладка приложения
if ($system_config->debug->on) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
ini_set('display_errors', 0);
}
//проверяем настройки для базы данных
if ($system_config->database) {
if (empty($system_config->database->adapter)) {
throw new \Exception('Database adapter is empty!', 500);
}
if (empty($system_config->database->params->dbname)) {
throw new \Exception('Database name is empty!', 500);
}
}
//конфиг стал только для чтения
$system_config->setReadOnly();
if (isset($system_config->include_path) && $system_config->include_path) {
set_include_path(get_include_path() . PATH_SEPARATOR . $system_config->include_path);
}
//подключаем мультиязычность
$translate = new I18n($system_config);
//сохраняем конфиг
Registry::set('config', $system_config);
//обрабатываем конфиг ядра
$core_conf_file = __DIR__ . "/conf.ini";
if (file_exists($core_conf_file)) {
$core_config = new Core2\Config();
Registry::set('core_config', $core_config->readIni($core_conf_file, 'production'));
}