-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
42 lines (34 loc) · 889 Bytes
/
api.php
File metadata and controls
42 lines (34 loc) · 889 Bytes
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
<?php
/**
* 入口文件
* 注意事项:
*/
// sleep(2);
// 载入依赖
include __DIR__.'/inc/config.php';
include __DIR__.'/inc/common.php';
// options请求
if($_SERVER['REQUEST_METHOD']==='OPTIONS'){
Common::response(100);
}
// 请求路径
$requestUrl = explode('/', $_SERVER['REQUEST_URI']);
// 模块路径
$path = __DIR__.'/route/'.$requestUrl[2].'.php';
// 进入路由
if(is_file($path)){
// 实例化类
include $path;
$controllerName = ucfirst($requestUrl[2]);
$controller = new $controllerName;
$method = $requestUrl[3];
// 执行请求
if(method_exists($controller, $method)){
$controller -> $method();
}else{
Common::response(404);
}
}else{
Common::response(404);
}
?>