-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoote.php
89 lines (76 loc) · 2.02 KB
/
Roote.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
/**
* 单一入口路由,根据传值调用类
*/
class Roote
{
private static $roote //存放对象
private $modul; //模块
private $class; //得到类存在的位置
private $func; //得到使用的函数名
private $value = array(); //函数参数
private $method; //数据传递方式
private function __construct(){
$this->getmethod();
$this->getval();
$this->path();
$this->runit();
}
/**
* 判断数据传递方式,并得到传递的数据
* @return void
*/
protected function getmethod()
{
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'POST':
$this->method = $_POST;
unset($_POST);
break;
default:
$this->method = $_GET;
unset($_GET);
break;
}
}
/**
* 从传递数据分离模块,类和方法的值
* @return void
*/
protected function getval()
{
$this->modul = isset($this->method['m'])?addslashes($this->method['m']):'clinets'; //模块
$this->class = isset($this->method['c'])?addslashes($this->method['c']):'index'; //类
$this->func = isset($this->method['c']?addslashes($this->method['f']):''; //方法
unset($this->method['m']);
unset($this->method['c']);
unset($this->method['f']);
$this->value = $this->method; //得到函数参数的值
}
/**
* 得到地址url将目标文件引入
* @return [type] [description]
*/
protected function path()
{
$path = './'.$this->modul.$this->class.'class.php'; //相对地址
if(!file_exists($path)) die("不存在该文件");
require_once($path);
}
/**
* 运行目标函数
* @return void
*/
protected function runit()
{
$pos = strrpos($this->class,'/'); //获取class 名字的位置
$class = substr($this->class, $pos + 1);//获取到class
if(!isset($this->func) && isset($this->value)) $obj = new $class($value);
else $obj = new $class();
if(isset($this->func)) {
$mark = call_user_func_array(array($obj, $this->func), $this->value); //判断是否成功
if($mark === false) exit("函数执行失败");
}
}
}