1 | <?php |
||
21 | class Map implements IteratorAggregate |
||
22 | { |
||
23 | /** |
||
24 | * |
||
25 | * An array of route objects. |
||
26 | * |
||
27 | * @var array |
||
28 | * |
||
29 | */ |
||
30 | protected $routes = []; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * A prototype Route. |
||
35 | * |
||
36 | * @var Route |
||
37 | * |
||
38 | */ |
||
39 | protected $protoRoute; |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * Constructor. |
||
44 | * |
||
45 | * @param Route $protoRoute A prototype Route. |
||
46 | * |
||
47 | */ |
||
48 | 22 | public function __construct(Route $protoRoute) |
|
52 | |||
53 | /** |
||
54 | * |
||
55 | * Proxy unknown method calls to the proto-route. |
||
56 | * |
||
57 | * @param string $method The method name. |
||
58 | * |
||
59 | * @param array $params The method params. |
||
60 | * |
||
61 | * @return $this |
||
62 | * |
||
63 | */ |
||
64 | 3 | public function __call($method, $params) |
|
65 | { |
||
66 | 3 | call_user_func_array([$this->protoRoute, $method], $params); |
|
67 | 3 | return $this; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | * IteratorAggregate: returns the iterator object. |
||
73 | * |
||
74 | * @return ArrayIterator |
||
75 | * |
||
76 | */ |
||
77 | 5 | public function getIterator() |
|
81 | |||
82 | /** |
||
83 | * |
||
84 | * Sets the array of route objects to use. |
||
85 | * |
||
86 | * @param array $routes Use this array of routes. |
||
87 | * |
||
88 | * @return null |
||
89 | * |
||
90 | * @see getRoutes() |
||
91 | * |
||
92 | */ |
||
93 | 1 | public function setRoutes(array $routes) |
|
97 | |||
98 | /** |
||
99 | * |
||
100 | * Gets the route collection. |
||
101 | * |
||
102 | * @return Map |
||
103 | * |
||
104 | * @see setRoutes() |
||
105 | * |
||
106 | */ |
||
107 | 3 | public function getRoutes() |
|
111 | |||
112 | /** |
||
113 | * |
||
114 | * Adds a pre-built route to the collection. |
||
115 | * |
||
116 | * @param Route $route The pre-built route. |
||
117 | * |
||
118 | * @return $this |
||
119 | * |
||
120 | * @throws Exception\RouteAlreadyExists when the route name is already |
||
121 | * mapped. |
||
122 | * |
||
123 | */ |
||
124 | 21 | public function addRoute(Route $route) |
|
139 | |||
140 | /** |
||
141 | * |
||
142 | * Gets a route by name. |
||
143 | * |
||
144 | * @param string $name The route name. |
||
145 | * |
||
146 | * @return Route |
||
147 | * |
||
148 | */ |
||
149 | 12 | public function getRoute($name) |
|
157 | |||
158 | /** |
||
159 | * |
||
160 | * Adds a generic route. |
||
161 | * |
||
162 | * @param string $name The route name. |
||
163 | * |
||
164 | * @param string $path The route path. |
||
165 | * |
||
166 | * @param mixed $handler The route leads to this handler. |
||
167 | * |
||
168 | * @return Route The newly-added route object. |
||
169 | * |
||
170 | */ |
||
171 | 21 | public function route($name, $path, $handler = null) |
|
180 | |||
181 | /** |
||
182 | * |
||
183 | * Adds a GET route. |
||
184 | * |
||
185 | * @param string $name The route name. |
||
186 | * |
||
187 | * @param string $path The route path. |
||
188 | * |
||
189 | * @param mixed $handler The route leads to this handler. |
||
190 | * |
||
191 | * @return Route The newly-added route object. |
||
192 | * |
||
193 | */ |
||
194 | 1 | public function get($name, $path, $handler = null) |
|
200 | |||
201 | /** |
||
202 | * |
||
203 | * Adds a DELETE route. |
||
204 | * |
||
205 | * @param string $name The route name. |
||
206 | * |
||
207 | * @param string $path The route path. |
||
208 | * |
||
209 | * @param mixed $handler The route leads to this handler. |
||
210 | * |
||
211 | * @return Route The newly-added route object. |
||
212 | * |
||
213 | */ |
||
214 | 2 | public function delete($name, $path, $handler = null) |
|
220 | |||
221 | /** |
||
222 | * |
||
223 | * Adds a HEAD route. |
||
224 | * |
||
225 | * @param string $name The route name. |
||
226 | * |
||
227 | * @param string $path The route path. |
||
228 | * |
||
229 | * @param mixed $handler The route leads to this handler. |
||
230 | * |
||
231 | * @return Route The newly-added route object. |
||
232 | * |
||
233 | */ |
||
234 | 1 | public function head($name, $path, $handler = null) |
|
240 | |||
241 | /** |
||
242 | * |
||
243 | * Adds an OPTIONS route. |
||
244 | * |
||
245 | * @param string $name The route name. |
||
246 | * |
||
247 | * @param string $path The route path. |
||
248 | * |
||
249 | * @param mixed $handler The route leads to this handler. |
||
250 | * |
||
251 | * @return Route The newly-added route object. |
||
252 | * |
||
253 | */ |
||
254 | 1 | public function options($name, $path, $handler = null) |
|
260 | |||
261 | /** |
||
262 | * |
||
263 | * Adds a PATCH route. |
||
264 | * |
||
265 | * @param string $name The route name. |
||
266 | * |
||
267 | * @param string $path The route path. |
||
268 | * |
||
269 | * @param mixed $handler The route leads to this handler. |
||
270 | * |
||
271 | * @return Route The newly-added route object. |
||
272 | * |
||
273 | */ |
||
274 | 1 | public function patch($name, $path, $handler = null) |
|
280 | |||
281 | /** |
||
282 | * |
||
283 | * Adds a POST route. |
||
284 | * |
||
285 | * @param string $name The route name. |
||
286 | * |
||
287 | * @param string $path The route path. |
||
288 | * |
||
289 | * @param mixed $handler The route leads to this handler. |
||
290 | * |
||
291 | * @return Route The newly-added route object. |
||
292 | * |
||
293 | */ |
||
294 | 3 | public function post($name, $path, $handler = null) |
|
300 | |||
301 | /** |
||
302 | * |
||
303 | * Adds a PUT route. |
||
304 | * |
||
305 | * @param string $name The route name. |
||
306 | * |
||
307 | * @param string $path The route path. |
||
308 | * |
||
309 | * @param mixed $handler The route leads to this handler. |
||
310 | * |
||
311 | * @return Route The newly-added route object. |
||
312 | * |
||
313 | */ |
||
314 | 1 | public function put($name, $path, $handler = null) |
|
320 | |||
321 | /** |
||
322 | * |
||
323 | * Attaches routes to a specific path prefix, and prefixes the attached |
||
324 | * route names. |
||
325 | * |
||
326 | * @param string $namePrefix The prefix for all route names being attached. |
||
327 | * |
||
328 | * @param string $pathPrefix The prefix for all route paths being attached. |
||
329 | * |
||
330 | * @param callable $callable A callable that uses the Map to add new |
||
331 | * routes. Its signature is `function (\Aura\Router\Map $map)`; $this |
||
332 | * Map instance will be passed to the callable. |
||
333 | * |
||
334 | * @return null |
||
335 | * |
||
336 | */ |
||
337 | 4 | public function attach($namePrefix, $pathPrefix, callable $callable) |
|
352 | } |
||
353 |