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|string|array $method as request method to support |
||
31 | * |
||
32 | * @return $this |
||
33 | */ |
||
34 | 17 | public function set($rule = null, $action = null, $method = null) |
|
46 | |||
47 | |||
48 | |||
49 | /** |
||
50 | * Check if part of route is a argument and optionally match type |
||
51 | * as a requirement {argument:type}. |
||
52 | * |
||
53 | * @param string $rulePart the rule part to check. |
||
54 | * @param string $queryPart the query part to check. |
||
55 | * @param array &$args add argument to args array if matched |
||
56 | * |
||
57 | * @return boolean |
||
58 | */ |
||
59 | 2 | private function checkPartAsArgument($rulePart, $queryPart, &$args) |
|
77 | |||
78 | |||
79 | |||
80 | /** |
||
81 | * Check if value is matching a certain type of values. |
||
82 | * |
||
83 | * @param string $rulePart the rule part to check. |
||
84 | * @param string $queryPart the query part to check. |
||
85 | * @param array &$args add argument to args array if matched |
||
86 | * |
||
87 | * @return boolean |
||
88 | */ |
||
89 | 1 | private function checkPartMatchingType($value, $type) |
|
112 | |||
113 | |||
114 | |||
115 | /** |
||
116 | * Match part of rule and query. |
||
117 | * |
||
118 | * @param string $rulePart the rule part to check. |
||
119 | * @param string $queryPart the query part to check. |
||
120 | * @param array &$args add argument to args array if matched |
||
121 | * |
||
122 | * @return boolean |
||
123 | */ |
||
124 | 15 | private function matchPart($rulePart, $queryPart, &$args) |
|
143 | |||
144 | |||
145 | |||
146 | /** |
||
147 | * Check if the request method matches. |
||
148 | * |
||
149 | * @param string $method as request method |
||
150 | * |
||
151 | * @return boolean true if request method matches |
||
152 | */ |
||
153 | 17 | public function matchRequestMethod($method) |
|
162 | |||
163 | |||
164 | |||
165 | /** |
||
166 | * Check if the route matches a query and request method. |
||
167 | * |
||
168 | * @param string $query to match against |
||
169 | * @param string $method as request method |
||
170 | * |
||
171 | * @return boolean true if query matches the route |
||
172 | */ |
||
173 | 17 | public function match($query, $method = null) |
|
202 | |||
203 | |||
204 | |||
205 | /** |
||
206 | * Handle the action for the route. |
||
207 | * |
||
208 | * @return void |
||
209 | */ |
||
210 | 10 | public function handle() |
|
214 | |||
215 | |||
216 | |||
217 | /** |
||
218 | * Set the name of the route. |
||
219 | * |
||
220 | * @param string $name set a name for the route |
||
221 | * |
||
222 | * @return $this |
||
223 | */ |
||
224 | public function setName($name) |
||
229 | |||
230 | |||
231 | |||
232 | /** |
||
233 | * Get the rule for the route. |
||
234 | * |
||
235 | * @return string |
||
236 | */ |
||
237 | 9 | public function getRule() |
|
241 | } |
||
242 |
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.