1 | <?php |
||
13 | class CallbackRoute extends Route { |
||
14 | /// Properties /// |
||
15 | |||
16 | /** |
||
17 | * |
||
18 | * @var callable The callback to call on a matching pattern. |
||
19 | */ |
||
20 | protected $callback; |
||
21 | |||
22 | /// Methods /// |
||
23 | |||
24 | /** |
||
25 | * Initialize an instance of the {@link CallbackRoute} class. |
||
26 | * |
||
27 | * @param string $pattern The pattern to match to. |
||
28 | * @param callable $callback The callback to call when the url matches. |
||
29 | */ |
||
30 | 10 | public function __construct($pattern, callable $callback) { |
|
34 | |||
35 | /** |
||
36 | * Dispatch the matched route and call its callback. |
||
37 | * |
||
38 | * @param Request $request The request to dispatch. |
||
39 | * @param array &$args The arguments returned from {@link CallbackRoute::dispatch()}. |
||
40 | * @return mixed Returns the result of the callback. |
||
41 | */ |
||
42 | 9 | public function dispatch(Request $request, array &$args) { |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 10 | public function matches(Request $request, Application $app) { |
|
82 | |||
83 | /** |
||
84 | * Convert a path pattern into its regex. |
||
85 | * |
||
86 | * @param string $pattern The route pattern to convert into a regular expression. |
||
87 | * @return string Returns the regex pattern for the route. |
||
88 | */ |
||
89 | protected function getPatternRegex($pattern) { |
||
108 | |||
109 | /** |
||
110 | * Get the callback for the route. |
||
111 | * |
||
112 | * @return callable Returns the current callback. |
||
113 | */ |
||
114 | public function getCallback() { |
||
117 | |||
118 | /** |
||
119 | * Set the callback for the route. |
||
120 | * |
||
121 | * @param callable $callback The new callback to set. |
||
122 | * @return CallbackRoute Retuns $this for fluent calls. |
||
123 | */ |
||
124 | 10 | public function setCallback(callable $callback) { |
|
128 | } |
||
129 | |||
130 |