-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
89 lines (69 loc) · 2.47 KB
/
bootstrap.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
<?php
namespace Core3;
use Core3\Classes\Registry;
use Core3\Classes\Config;
use Core3\Classes\Tools;
use Core3\Classes\Translate;
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ALL);
ini_set('display_errors', true);
define('DOC_ROOT', realpath(__DIR__ . '/..'));
define("DOC_PATH", substr(DOC_ROOT, strlen($_SERVER['DOCUMENT_ROOT'])) ? : '/');
$conf_file = DOC_ROOT . "/conf.ini";
if ( ! file_exists($conf_file)) {
throw new \Exception("Missing configuration file '{$conf_file}'.");
}
if (PHP_SAPI === 'cli') {
//определяем имя секции для cli режима
$options = getopt('m:e:p:l:nct:avhd', [
'module:',
'method:',
'param:',
'cli-methods',
'worker-start',
'worker-stop',
'modules',
'composer',
'host',
'openapi',
'version',
'help',
]);
if (( ! empty($options['host']) && is_string($options['host'])) ||
( ! empty($options['t']) && is_string($options['t']))
) {
$_SERVER['SERVER_NAME'] = ! empty($options['host']) ? $options['host'] : $options['t'];
}
// если выполняется действие с кампоузером, то дальше исполнять код не нужно
if (isset($options['c']) || isset($options['composer'])) {
return '';
}
}
$vendor_autoload_file = "vendor/autoload.php";
if ( ! file_exists($vendor_autoload_file)) {
throw new \Exception("No external libraries. You need to execute in the console: php " . DOC_ROOT . "/index.php --composer -p update");
}
require_once $vendor_autoload_file;
require_once 'autoload.php';
$config = new Config();
$config->addFileIni(__DIR__ . "/conf.ini", 'production');
$config->addFileIni($conf_file, $_SERVER['SERVER_NAME'] ?? 'production');
$config->system->cache->dir = $config->system?->cache?->dir
? Tools::getAbsolutePath($config->system->cache->dir)
: null;
$config->system->tmp = $config->system?->tmp
? Tools::getAbsolutePath($config->system->tmp)
: sys_get_temp_dir();
if ($config->system?->log?->dir) {
$config->system->log->dir = Tools::getAbsolutePath($config->system->log->dir);
}
$config->setReadOnly();
// отладка приложения
if ($config?->system?->debug?->on) {
error_reporting(E_ALL);
ini_set('display_errors', true);
} else {
ini_set('display_errors', false);
}
Registry::set('config', $config);
Registry::set('translate', new Translate($config));