1 | <?php |
||
12 | class Router |
||
13 | { |
||
14 | const _ext = '?ext'; |
||
15 | const _sep = "\x1E"; |
||
16 | |||
17 | /** @var \Teto\Routing\Action[] */ |
||
18 | public $variable_actions = []; |
||
19 | |||
20 | /** @var \Teto\Routing\Action[][] */ |
||
21 | public $fixed_actions = []; |
||
22 | |||
23 | /** @var \Teto\Routing\Action[] */ |
||
24 | public $named_actions = []; |
||
25 | |||
26 | /** @var array */ |
||
27 | public $error_action = []; |
||
28 | |||
29 | public function __set($name, $value) |
||
30 | { |
||
31 | throw new \OutOfRangeException("Unexpected key:'$name'"); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param array $route_map |
||
36 | * @param string $method |
||
37 | * @param string $path |
||
38 | * @return \Teto\Routing\Action |
||
39 | */ |
||
40 | 24 | public static function dispatch(array $route_map, $method, $path) |
|
44 | |||
45 | /** |
||
46 | * @param array $route_map |
||
47 | */ |
||
48 | 24 | public function __construct(array $route_map) |
|
56 | |||
57 | /** |
||
58 | * @param string $method |
||
59 | * @param string $path |
||
60 | * @return \Teto\Routing\Action |
||
61 | */ |
||
62 | 48 | public function match($method, $path) |
|
103 | |||
104 | /** |
||
105 | * @param string $method |
||
106 | * @param string $path |
||
107 | * @return \Teto\Routing\Action |
||
108 | */ |
||
109 | 24 | public function getNotFoundAction($method, $path) |
|
110 | { |
||
111 | 24 | $split_path = array_values(array_filter(explode('/', $path), 'strlen')); |
|
112 | |||
113 | 24 | return new NotFoundAction( |
|
114 | 24 | [$method], |
|
115 | 24 | $split_path, |
|
116 | 24 | [], |
|
117 | 24 | [], |
|
118 | 24 | $this->error_action['#404'] |
|
119 | ); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param int|string $key |
||
124 | * @param array $action_tuple |
||
125 | */ |
||
126 | 24 | public function setAction($key, array $action_tuple) |
|
158 | |||
159 | /** |
||
160 | * @param string $name |
||
161 | * @param mixed $value |
||
162 | */ |
||
163 | 24 | public function setSpecialAction($name, $value) |
|
167 | |||
168 | /** |
||
169 | * @param string $name |
||
170 | * @param array $param |
||
171 | * @param boolean $strict |
||
172 | */ |
||
173 | 15 | public function makePath($name, array $param = [], $strict = false) |
|
188 | } |
||
189 |