1 | <?php |
||
13 | class RouteConfig extends AbstractConfig |
||
14 | { |
||
15 | /** |
||
16 | * Route identifier/name |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | private $ident; |
||
21 | |||
22 | /** |
||
23 | * Route pattern |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $route; |
||
28 | |||
29 | /** |
||
30 | * HTTP methods supported by this route |
||
31 | * |
||
32 | * @var string[] |
||
33 | */ |
||
34 | private $methods = [ 'GET' ]; |
||
35 | |||
36 | /** |
||
37 | * Response controller classname |
||
38 | * |
||
39 | * Should be the class-ident of an action, a script or a template controller. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $controller; |
||
44 | |||
45 | /** |
||
46 | * Parent route groups |
||
47 | * |
||
48 | * @var string[] |
||
49 | */ |
||
50 | private $groups = []; |
||
51 | |||
52 | /** |
||
53 | * Optional headers to set on response. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | private $headers = []; |
||
58 | |||
59 | /** |
||
60 | * Retrieve the default route types. |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | public static function defaultRouteTypes() |
||
72 | |||
73 | /** |
||
74 | * Set route identifier |
||
75 | * |
||
76 | * @param string $ident Route identifier. |
||
77 | * @throws InvalidArgumentException If the identifier is not a string. |
||
78 | * @return self |
||
79 | */ |
||
80 | public function setIdent($ident) |
||
92 | |||
93 | /** |
||
94 | * Get route identifier |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | public function ident() |
||
102 | |||
103 | /** |
||
104 | * Set route pattern. |
||
105 | * |
||
106 | * @param string $pattern Route pattern. |
||
107 | * @throws InvalidArgumentException If the pattern argument is not a string. |
||
108 | * @return self |
||
109 | */ |
||
110 | public function setRoute($pattern) |
||
122 | |||
123 | /** |
||
124 | * Get route pattern |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | public function route() |
||
132 | |||
133 | /** |
||
134 | * Set parent route groups |
||
135 | * |
||
136 | * @param string[] $groups The parent route groups. |
||
137 | * @return self |
||
138 | */ |
||
139 | public function setGroups(array $groups) |
||
149 | |||
150 | /** |
||
151 | * Add parent route group |
||
152 | * |
||
153 | * @param string $group The parent route group. |
||
154 | * @throws InvalidArgumentException If the group is invalid. |
||
155 | * @return self |
||
156 | */ |
||
157 | public function addGroup($group) |
||
169 | |||
170 | /** |
||
171 | * Get parent route groups |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | public function groups() |
||
179 | |||
180 | /** |
||
181 | * Add custom headers |
||
182 | * |
||
183 | * @param array $headers The custom headers, in key=>val pairs. |
||
184 | * @return self |
||
185 | */ |
||
186 | public function setHeaders(array $headers) |
||
194 | |||
195 | /** |
||
196 | * @param string $name The header name (ex: "Content-Type", "Cache-Control"). |
||
197 | * @param string $val The header value. |
||
198 | * @throws InvalidArgumentException If the header name or value is not a string. |
||
199 | * @return $this |
||
200 | */ |
||
201 | public function addHeader($name, $val) |
||
216 | |||
217 | /** |
||
218 | * Get custom route headers. |
||
219 | * |
||
220 | * @return array |
||
221 | */ |
||
222 | public function headers() |
||
226 | |||
227 | /** |
||
228 | * Set route view controller classname |
||
229 | * |
||
230 | * @param string $controller Route controller name. |
||
231 | * @throws InvalidArgumentException If the route view controller is not a string. |
||
232 | * @return self |
||
233 | */ |
||
234 | public function setController($controller) |
||
246 | |||
247 | /** |
||
248 | * Get the view controller classname |
||
249 | * |
||
250 | * If not set, the `self::ident()` will be used by default. |
||
251 | * |
||
252 | * @return string |
||
253 | */ |
||
254 | public function controller() |
||
262 | |||
263 | /** |
||
264 | * Set route methods |
||
265 | * |
||
266 | * @param string[] $methods The route's supported HTTP methods. |
||
267 | * @return self |
||
268 | */ |
||
269 | public function setMethods(array $methods) |
||
279 | |||
280 | /** |
||
281 | * Add route HTTP method. |
||
282 | * |
||
283 | * @param string $method The route's supported HTTP method. |
||
284 | * @throws InvalidArgumentException If the HTTP method is invalid. |
||
285 | * @return self |
||
286 | */ |
||
287 | public function addMethod($method) |
||
325 | |||
326 | /** |
||
327 | * Get route methods |
||
328 | * |
||
329 | * @return string[] |
||
330 | */ |
||
331 | public function methods() |
||
335 | } |
||
336 |