1 | <?php |
||
9 | class Route |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Properties |
||
14 | * |
||
15 | */ |
||
16 | private $name; // A name for this route |
||
17 | private $method; // The methods to support |
||
18 | private $rule; // The rule for this route |
||
19 | private $action; // The callback to handle this route |
||
20 | private $arguments = []; // Arguments for the callback |
||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * Set values for route. |
||
26 | * |
||
27 | * @param string $rule for this route |
||
28 | * @param callable $action callable to implement a controller for |
||
29 | * the route |
||
30 | * @param null|array $method as request method to support |
||
31 | * |
||
32 | * @return $this |
||
33 | */ |
||
34 | 14 | public function set($rule, $action, $method = null) |
|
42 | |||
43 | |||
44 | |||
45 | /** |
||
46 | * Check if part of route is a argument and optionally match type |
||
47 | * as a requirement {argument:type}. |
||
48 | * |
||
49 | * @param string $rulePart the rule part to check. |
||
50 | * @param string $queryPart the query part to check. |
||
51 | * @param array &$args add argument to args array if matched |
||
52 | * |
||
53 | * @return boolean |
||
54 | */ |
||
55 | 2 | private function checkPartAsArgument($rulePart, $queryPart, &$args) |
|
73 | |||
74 | |||
75 | |||
76 | /** |
||
77 | * Check if value is matching a certain type of values. |
||
78 | * |
||
79 | * @param string $rulePart the rule part to check. |
||
80 | * @param string $queryPart the query part to check. |
||
81 | * @param array &$args add argument to args array if matched |
||
82 | * |
||
83 | * @return boolean |
||
84 | */ |
||
85 | 1 | private function checkPartMatchingType($value, $type) |
|
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * Match part of rule and query. |
||
113 | * |
||
114 | * @param string $rulePart the rule part to check. |
||
115 | * @param string $queryPart the query part to check. |
||
116 | * @param array &$args add argument to args array if matched |
||
117 | * |
||
118 | * @return boolean |
||
119 | */ |
||
120 | 12 | private function matchPart($rulePart, $queryPart, &$args) |
|
139 | |||
140 | |||
141 | |||
142 | /** |
||
143 | * Check if the request method matches. |
||
144 | * |
||
145 | * @param string $method as request method |
||
146 | * |
||
147 | * @return boolean true if request method matches |
||
148 | */ |
||
149 | 14 | public function matchRequestMethod($method) |
|
158 | |||
159 | |||
160 | |||
161 | /** |
||
162 | * Check if the route matches a query and request method. |
||
163 | * |
||
164 | * @param string $query to match against |
||
165 | * @param string $method as request method |
||
166 | * |
||
167 | * @return boolean true if query matches the route |
||
168 | */ |
||
169 | 14 | public function match($query, $method = null) |
|
198 | |||
199 | |||
200 | |||
201 | /** |
||
202 | * Handle the action for the route. |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | 9 | public function handle() |
|
210 | |||
211 | |||
212 | |||
213 | /** |
||
214 | * Set the name of the route. |
||
215 | * |
||
216 | * @param string $name set a name for the route |
||
217 | * |
||
218 | * @return $this |
||
219 | */ |
||
220 | public function setName($name) |
||
225 | |||
226 | |||
227 | |||
228 | /** |
||
229 | * Get the rule for the route. |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | 8 | public function getRule() |
|
237 | } |
||
238 |
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.