-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
54 lines (43 loc) · 1.22 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
<?php
//设置时区
date_default_timezone_set('PRC');
//全局设置
include_once('miniphp/config/Config.php');
//Model基类
include_once('miniphp/Model.php');
//控制器基类
include_once('miniphp/Controller.php');
//自定义路由
include_once('miniphp/Route.php');
//Psr4自动加载
include_once('miniphp/core/Psr4AutoLoad.php');
include_once('miniphp/utils/Safe.php');
//项目地址
define('__APP_PATH__', (__DIR__ . '/'));
$url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
define('__URL__', $url);
$route = new \miniphp\Route();
$psr = new \miniphp\core\Psr4AutoLoad();
//执行自定义路由
$url = $route->run();
//处理URL
$url = explode('/', $url);
//c(Controller)转换为全小写 首字母大写,默认值为Index,a(Action)方法名
$c = @$url[1] ? ucfirst(strtolower($url[1])) : 'Index';
$a = @$url[2] ? $url[2] : 'index';
//拼接带有命名空间的类名
$controller = '\\controller\\' . $c . 'Controller';
//添加命名空间映射
$psr->addMap('controller', 'app/controller');
$psr->addMap('model', 'app/model');
$class = new $controller();
//判断方法是否存在
if(method_exists($class, $a))
{
//调用目标方法
call_user_func([$class, $a]);
}
else
{
die($c . '/' . $a . ' 方法不存在');
}