-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
155 lines (131 loc) · 4.92 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
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
151
152
153
154
155
<?php
use core\Api;
use core\Cache;
use core\Log;
/*
84PHP开源框架
©2022 84PHP.com
框架版本号:6.1.0
*/
const __VERSION__ = '6.1.0';
define('__TIME__', microtime(true));
define('__ROOT__', str_replace(['\\', '//'], '/', dirname(__FILE__)));
register_shutdown_function("fatalErrorHandler");
set_error_handler('systemErrorHandler', E_ALL | E_STRICT);
const E_FATAL = E_ERROR | E_USER_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
set_include_path(get_include_path() . PATH_SEPARATOR . __ROOT__ . '/lib/');
$_SERVER['84PHP'] = ['Config' => [], 'Log' => [], 'Option' => [], 'Runtime' => [], 'URI' => ''];
require(__ROOT__ . '/config/base.php');
define('__DEBUG__', $_SERVER['84PHP']['Config']['Base']['debug']);
spl_autoload_register(
function ($ClassName) {
if (!file_exists(__ROOT__ . '/lib/' . str_replace(['\\', '//'], '/', $ClassName) . '.php')) {
Api::wrong(['level' => 'F', 'detail' => 'Error#C.0.5' . "\r\n\r\n @ " . $ClassName, 'code' => 'C.0.5']);
} else {
if (file_exists(__ROOT__ . '/config/' . str_replace(['\\', '//'], '/', $ClassName) . '.php')) {
require(__ROOT__ . '/config/' . str_replace(['\\', '//'], '/', $ClassName) . '.php');
}
require(__ROOT__ . '/lib/' . str_replace(['\\', '//'], '/', $ClassName) . '.php');
}
}
);
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
die('OPTIONS request blocked by framework.');
}
date_default_timezone_set($_SERVER['84PHP']['Config']['Base']['timeZone']);
if ($_SERVER['84PHP']['Config']['Base']['timeLimit'] !== false) {
set_time_limit($_SERVER['84PHP']['Config']['Base']['timeLimit']);
}
if ($_SERVER['84PHP']['Config']['Base']['https']) {
if (!isset($_SERVER['HTTPS'])) {
Api::wrong(['level' => 'F', 'detail' => 'Error#C.0.6', 'code' => 'C.0.6']);
}
if ($_SERVER['HTTPS'] == '' || $_SERVER['HTTPS'] == 'off') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST__URI__']);
}
}
if (!__DEBUG__) {
error_reporting(0);
} else {
header('Cache-Control: no-cache,must-revalidate');
header('Pragma: no-cache');
header("Expires: -1");
header('Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT');
}
// 错误处理
function fatalErrorHandler()
{
$Error = error_get_last();
if ($Error && ($Error["type"] === ($Error["type"] & E_FATAL))) {
systemErrorHandler($Error["type"], $Error["message"], $Error["file"], $Error["line"]);
}
}
function systemErrorHandler($ErrorNo, $ErrorMsg, $ErrorFile, $ErrorLine): bool
{
if (error_reporting() == 0) {
return true;
}
switch ($ErrorNo) {
case E_WARNING:
$PHPSystemError = 'PHP Warning: ';
break;
case E_NOTICE:
$PHPSystemError = 'PHP Notice: ';
break;
case E_DEPRECATED:
$PHPSystemError = 'PHP Deprecated: ';
break;
case E_USER_ERROR:
$PHPSystemError = 'User Error: ';
break;
case E_USER_WARNING:
$PHPSystemError = 'User Warning: ';
break;
case E_USER_NOTICE:
$PHPSystemError = 'User Notice: ';
break;
case E_USER_DEPRECATED:
$PHPSystemError = 'User Deprecated: ';
break;
case E_STRICT:
$PHPSystemError = 'PHP Strict: ';
break;
default:
$PHPSystemError = 'Unknown error: ';
break;
}
$PHPSystemError .= $ErrorMsg . ' in ' . str_replace('\\', '/', $ErrorFile) . ' on ' . $ErrorLine;
Api::wrong(['level' => 'S', 'detail' => 'Error#C.0.2 @ ' . $PHPSystemError, 'code' => 'C.0.2']);
return true;
}
//缓冲区控制开启
ob_start();
//路由
$_SERVER['84PHP']['URI'] = '';
$_SERVER['84PHP']['Option'] = getopt('', ['path:']);
if (empty($_SERVER['84PHP']['Option']['path'])) {
if (!isset($_GET['p_a_t_h'])) {
$_GET['p_a_t_h'] = '';
}
$_SERVER['84PHP']['URI'] = $_GET['p_a_t_h'];
} else {
$_SERVER['84PHP']['URI'] = $_SERVER['84PHP']['Option']['path'];
}
define('__URI__', $_SERVER['84PHP']['URI']);
Cache::compile(['path' => __URI__]);
if (file_exists(__ROOT__ . '/temp/cache' . __URI__ . '.php')) {
require(__ROOT__ . '/temp/cache' . __URI__ . '.php');
} elseif (file_exists(__ROOT__ . '/web' . __URI__ . '/index.html')) {
$Content = file_get_contents(__ROOT__ . '/web' . __URI__ . '/index.html');
echo($Content);
} elseif (file_exists(__ROOT__ . '/web' . __URI__ . '/index.htm')) {
$Content = file_get_contents(__ROOT__ . '/web' . __URI__ . '/index.htm');
echo($Content);
} elseif (!empty($_SERVER['84PHP']['Config']['Base']['pageNotFound'])) {
header('Location: ' . $_SERVER['84PHP']['Config']['Base']['pageNotFound']);
} else {
Api::wrong(['level' => 'U', 'detail' => 'Error#C.0.0', 'code' => 'C.0.0', 'http' => 404]);
}
if (!empty($_SERVER['84PHP']['Log'])) {
Log::output();
}