1 | <?php |
||
9 | class Route |
||
10 | { |
||
11 | /** |
||
12 | * @var string $name a name for this route. |
||
13 | * @var string|array $method the method(s) to support |
||
14 | * @var string $rule the path rule for this route |
||
15 | * @var callable $action the callback to handle this route |
||
16 | * @var null|array $arguments arguments for the callback, extracted |
||
17 | * from path |
||
18 | */ |
||
19 | private $name; |
||
20 | private $method; |
||
21 | private $rule; |
||
22 | private $action; |
||
23 | private $arguments = []; |
||
24 | |||
25 | |||
26 | |||
27 | /** |
||
28 | * Set values for route. |
||
29 | * |
||
30 | * @param null|string $rule for this route |
||
31 | * @param callable $action callable to implement a controller for |
||
32 | * the route |
||
33 | * @param null|string|array $method as request method to support |
||
34 | * |
||
35 | * @return $this |
||
36 | */ |
||
37 | 37 | public function set($rule, $action = null, $method = null) |
|
49 | |||
50 | |||
51 | |||
52 | /** |
||
53 | * Check if part of route is a argument and optionally match type |
||
54 | * as a requirement {argument:type}. |
||
55 | * |
||
56 | * @param string $rulePart the rule part to check. |
||
57 | * @param string $queryPart the query part to check. |
||
58 | * @param array &$args add argument to args array if matched |
||
59 | * |
||
60 | * @return boolean |
||
61 | */ |
||
62 | 7 | private function checkPartAsArgument($rulePart, $queryPart, &$args) |
|
80 | |||
81 | |||
82 | |||
83 | /** |
||
84 | * Check if value is matching a certain type of values. |
||
85 | * |
||
86 | * @param string $value the value to check. |
||
87 | * @param array $type the expected type to check against. |
||
88 | * |
||
89 | * @return boolean |
||
90 | */ |
||
91 | private function checkPartMatchingType($value, $type) |
||
114 | |||
115 | |||
116 | |||
117 | /** |
||
118 | * Check if value is matching a certain type and do type |
||
119 | * conversion accordingly. |
||
120 | * |
||
121 | * @param string $value the value to check. |
||
122 | * @param array $type the expected type to check against. |
||
123 | * |
||
124 | * @return boolean |
||
125 | */ |
||
126 | private function typeConvertArgument($value, $type) |
||
137 | 7 | ||
138 | 7 | ||
139 | |||
140 | 29 | /** |
|
141 | 29 | * Match part of rule and query. |
|
142 | 29 | * |
|
143 | 29 | * @param string $rulePart the rule part to check. |
|
144 | 30 | * @param string $queryPart the query part to check. |
|
145 | * @param array &$args add argument to args array if matched |
||
146 | * |
||
147 | * @return boolean |
||
148 | */ |
||
149 | private function matchPart($rulePart, $queryPart, &$args) |
||
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * Check if the request method matches. |
||
173 | * |
||
174 | * @param string $method as request method |
||
175 | * |
||
176 | 36 | * @return boolean true if request method matches |
|
177 | */ |
||
178 | 36 | public function matchRequestMethod($method) |
|
187 | |||
188 | |||
189 | |||
190 | 30 | /** |
|
191 | 30 | * Check if the route matches a query and request method. |
|
192 | 30 | * |
|
193 | 30 | * @param string $query to match against |
|
194 | * @param string $method as request method |
||
195 | 30 | * |
|
196 | 30 | * @return boolean true if query matches the route |
|
197 | 30 | */ |
|
198 | public function match($query, $method = null) |
||
233 | |||
234 | |||
235 | |||
236 | /** |
||
237 | * Handle the action for the route. |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | public function handle() |
||
245 | |||
246 | 24 | ||
247 | |||
248 | 24 | /** |
|
249 | * Set the name of the route. |
||
250 | * |
||
251 | * @param string $name set a name for the route |
||
252 | * |
||
253 | * @return $this |
||
254 | */ |
||
255 | public function setName($name) |
||
260 | |||
261 | |||
262 | |||
263 | /** |
||
264 | * Get the rule for the route. |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | public function getRule() |
||
272 | } |
||
273 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.