|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace micro\controllers\admin\popo; |
|
4
|
|
|
|
|
5
|
|
|
class Route { |
|
6
|
|
|
private $path; |
|
7
|
|
|
private $controller; |
|
8
|
|
|
private $action; |
|
9
|
|
|
private $parameters=[]; |
|
10
|
|
|
private $cache; |
|
11
|
|
|
private $duration; |
|
12
|
|
|
private $name; |
|
13
|
|
|
private $methods; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct($path="",$array=[]){ |
|
16
|
|
|
$this->path=$path; |
|
17
|
|
|
if(isset($array["controller"])){ |
|
18
|
|
|
$this->fromArray($array); |
|
19
|
|
|
}else{ |
|
20
|
|
|
$this->methods=\array_keys($array); |
|
21
|
|
|
$this->fromArray(\reset($array)); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
private function fromArray($array){ |
|
26
|
|
|
$this->controller=$array["controller"]; |
|
27
|
|
|
$this->action=$array["action"]; |
|
28
|
|
|
$this->name=$array["name"]; |
|
29
|
|
|
$this->cache=$array["cache"]; |
|
30
|
|
|
$this->duration=$array["duration"]; |
|
31
|
|
|
if(\sizeof($array["parameters"])>0){ |
|
32
|
|
|
$method=new \ReflectionMethod($this->controller,$this->action); |
|
33
|
|
|
$params=$method->getParameters(); |
|
34
|
|
|
foreach ($array["parameters"] as $param){ |
|
35
|
|
|
$this->parameters[]=$params[$param]->getName(); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getPath() { |
|
41
|
|
|
return $this->path; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function setPath($path) { |
|
45
|
|
|
$this->path=$path; |
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getController() { |
|
50
|
|
|
return $this->controller; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setController($controller) { |
|
54
|
|
|
$this->controller=$controller; |
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getAction() { |
|
59
|
|
|
return $this->action; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function setAction($action) { |
|
63
|
|
|
$this->action=$action; |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getParameters() { |
|
68
|
|
|
return $this->parameters; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function setParameters($parameters) { |
|
72
|
|
|
$this->parameters=$parameters; |
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getCache() { |
|
77
|
|
|
return $this->cache; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function setCache($cache) { |
|
81
|
|
|
$this->cache=$cache; |
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getDuration() { |
|
86
|
|
|
return $this->duration; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setDuration($duration) { |
|
90
|
|
|
$this->duration=$duration; |
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getName() { |
|
95
|
|
|
return $this->name; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setName($name) { |
|
99
|
|
|
$this->name=$name; |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public static function init($array){ |
|
104
|
|
|
$result=[]; |
|
105
|
|
|
foreach ($array as $k=>$v){ |
|
106
|
|
|
$result[]=new Route($k, $v); |
|
107
|
|
|
} |
|
108
|
|
|
return $result; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|