-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·71 lines (55 loc) · 1.67 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
<?php
define('ROOT', __DIR__);
date_default_timezone_set('Asia/Shanghai');
require 'start.php';
try {
error_reporting(E_ALL);
ini_set('display_errors', '1');
//将出错信息输出到一个文本文件
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
// if (!isset($_GET['token']) || !isset($_GET['uuid'])) {
//
// }
// Token::check($_GET['token'], $_GET['uuid']);
// UserModel::checkLogin($_GET['uuid']);
\DB::config(config('DB'));
$controller = APP::getController();
$response = $controller->execute(APP::getRequest());
Response::send($response);
} catch (Exception $e) {
Response::error($e);
}
function config($key)
{
static $config = array();
if (empty($config)) {
$config = require ROOT . DIRECTORY_SEPARATOR . 'config/config.php';
}
return isset($config[$key]) ? $config[$key] : '';
}
class App
{
public static function getController()
{
if (!isset($_SERVER['PATH_INFO'])) {
throw new Exception('php info error', 2000);
}
list($version, $module, $controller) = explode('/', ltrim($_SERVER['PATH_INFO'], '/'));
$file = ROOT . DIRECTORY_SEPARATOR
. 'app' . DIRECTORY_SEPARATOR
. $version . DIRECTORY_SEPARATOR
. ucfirst($module) . DIRECTORY_SEPARATOR
. ucfirst($controller) . '.php';
$class = ucfirst($module) . ucfirst($controller) . 'Controller';
if (!is_file($file)) {
throw new Exception('controller not find', 2001);
}
require $file;
return new $class();
}
public static function getRequest()
{
return $_POST + $_GET + $_FILES;
}
}
?>