1 | <?php |
||
23 | class Route implements ArrayAccess |
||
24 | { |
||
25 | /** |
||
26 | * @var mixed[] map of parameter-names to values collected during traversal |
||
27 | */ |
||
28 | public $vars = array(); |
||
29 | |||
30 | /** |
||
31 | * @var Module the Module to which this Route belongs |
||
32 | */ |
||
33 | public $module; |
||
34 | |||
35 | /** |
||
36 | * @var Route|null parent Route; or null if this is the root-Route. |
||
37 | */ |
||
38 | public $parent; |
||
39 | |||
40 | /** |
||
41 | * @var string the token that was matched when this Route was constructed. |
||
42 | */ |
||
43 | public $token; |
||
44 | |||
45 | /** |
||
46 | * @var string the (partial) path associated with this Route. |
||
47 | */ |
||
48 | public $path; |
||
49 | |||
50 | /** |
||
51 | * @var bool true, if routing has been explicitly aborted |
||
52 | */ |
||
53 | public $aborted; |
||
54 | |||
55 | /** |
||
56 | * @var Closure[] map of patterns to Route definition-functions |
||
57 | * |
||
58 | * @see resolve() |
||
59 | */ |
||
60 | protected $patterns = array(); |
||
61 | |||
62 | /** |
||
63 | * @var Closure[] map of method-names to functions |
||
64 | * |
||
65 | * @see execute() |
||
66 | */ |
||
67 | protected $methods = array(); |
||
68 | |||
69 | /** |
||
70 | * @var Module|null a Module instance being delegated to |
||
71 | * |
||
72 | * @see delegate() |
||
73 | */ |
||
74 | private $_delegate; |
||
75 | |||
76 | /** |
||
77 | * @param Route $parent parent Route |
||
78 | * @param string $token the token (partial path) that was matched when this Route was constructed. |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | 1 | protected function setParent(Route $parent, $token) |
|
91 | |||
92 | /** |
||
93 | * Sends a log entry to the parent Module for diagnostic purposes. |
||
94 | * |
||
95 | * Note that this has no effect unless the parent Module has a defined {@link Module::$onLog} callback. |
||
96 | * |
||
97 | * @param string $message |
||
98 | * |
||
99 | * @see Module::$onLog |
||
100 | */ |
||
101 | 1 | public function log($message) |
|
107 | |||
108 | /** |
||
109 | * @param string $pattern |
||
110 | * @param Closure $init |
||
111 | * |
||
112 | * @return void |
||
113 | * |
||
114 | * @see ArrayAccess::offsetSet() |
||
115 | */ |
||
116 | 1 | public function offsetSet($pattern, $init) |
|
121 | |||
122 | /** |
||
123 | * @param string $pattern |
||
124 | * |
||
125 | * @return bool |
||
126 | * |
||
127 | * @see ArrayAccess::offsetExists() |
||
128 | */ |
||
129 | 1 | public function offsetExists($pattern) |
|
133 | |||
134 | /** |
||
135 | * @param string $pattern |
||
136 | * |
||
137 | * @return void |
||
138 | * |
||
139 | * @see ArrayAccess::offsetUnset() |
||
140 | */ |
||
141 | 1 | public function offsetUnset($pattern) |
|
145 | |||
146 | /** |
||
147 | * @param string $pattern |
||
148 | * |
||
149 | * @return string |
||
150 | * |
||
151 | * @see ArrayAccess::offsetGet() |
||
152 | */ |
||
153 | 1 | public function offsetGet($pattern) |
|
157 | |||
158 | /** |
||
159 | * @param string $name HTTP method-name ("get", "head", "post", "put", "delete", etc.) |
||
160 | * |
||
161 | * @return Closure |
||
162 | */ |
||
163 | 1 | public function __get($name) |
|
171 | |||
172 | /** |
||
173 | * @param string $name HTTP method-name ("get", "head", "post", "put", "delete", etc.) |
||
174 | * @param Closure $value HTTP method callback |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | 1 | public function __set($name, $value) |
|
186 | |||
187 | /** |
||
188 | * Follow a (relative) path, walking from this Route to a destination Route. |
||
189 | * |
||
190 | * @param string $path relative path |
||
191 | * |
||
192 | * @return Route|null returns the resolved Route, or null if no Route was matched |
||
193 | * |
||
194 | * @throws RoutingException if a bad Route is encountered |
||
195 | */ |
||
196 | 1 | public function resolve($path) |
|
312 | |||
313 | /** |
||
314 | * Execute an HTTP method callback with a given name, and return the result. |
||
315 | * |
||
316 | * @param $method string name of HTTP method-handler to execute (e.g. 'get', 'put', 'post', 'delete', etc.) |
||
317 | * |
||
318 | * @return mixed|bool the value returned by the HTTP method-handler; true if the method-handler returned |
||
319 | * no value - or false if the method-handler was not found (or returned false) |
||
320 | */ |
||
321 | 1 | public function execute($method = 'get') |
|
335 | |||
336 | /** |
||
337 | * Delegate control to a different Module. |
||
338 | * |
||
339 | * When called from a route definition function, while resolving a route, control |
||
340 | * will be delegated to the given Module, meaning routing will continue for the |
||
341 | * remainder of the unresolve URL tokens within a given Module. |
||
342 | * |
||
343 | * This provides a means of creating modular routers, in which a subset of routes |
||
344 | * is packaged into a class derived from Module. (This approach also provides |
||
345 | * convenient reuse.) |
||
346 | * |
||
347 | * @param Module $module a Module to which to delegate the routing during resolve() |
||
348 | */ |
||
349 | 1 | public function delegate(Module $module) |
|
353 | |||
354 | /** |
||
355 | * Call this method to manually abort any further routing and abort from the |
||
356 | * current URL being resolved. |
||
357 | */ |
||
358 | 1 | public function abort() |
|
362 | |||
363 | /** |
||
364 | * When a URL token has been resolved, this function is called to generate the |
||
365 | * next Route instance to be configured by the route callback function. |
||
366 | * |
||
367 | * @param Route $parent |
||
368 | * @param string $token |
||
369 | * |
||
370 | * @return Route |
||
371 | */ |
||
372 | 1 | protected function createRoute(Route $parent, $token) |
|
385 | |||
386 | /** |
||
387 | * Invoke a function using variables collected during traversal. |
||
388 | * |
||
389 | * @param Closure $func the function to be invoked. |
||
390 | * |
||
391 | * @return mixed the value returned by the invoked function |
||
392 | * |
||
393 | * @throws InvocationException |
||
394 | * |
||
395 | * @see $vars |
||
396 | */ |
||
397 | 1 | protected function invoke($func) |
|
401 | } |
||
402 |