1 | <?php |
||
17 | class Router implements \SplObserver |
||
18 | { |
||
19 | /** |
||
20 | * @var \BFW\Module $module The bfw module instance for this module |
||
21 | */ |
||
22 | protected $module; |
||
23 | |||
24 | /** |
||
25 | * @var \BFW\Config $config The bfw config instance for this module |
||
26 | */ |
||
27 | protected $config; |
||
28 | |||
29 | /** |
||
30 | * @var \BFW\ControllerRouterLink $routerLinker Linker between |
||
31 | * controller and router instance |
||
32 | */ |
||
33 | protected $routerLinker; |
||
34 | |||
35 | /** |
||
36 | * @var \FastRoute\Dispatcher $dispatcher FastRoute dispatcher |
||
37 | */ |
||
38 | protected $dispatcher; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | * Get config and linker instance |
||
43 | * Call fastRoute dispatcher |
||
44 | * |
||
45 | * @param \BFW\Module $module |
||
46 | */ |
||
47 | public function __construct(\BFW\Module $module) |
||
59 | |||
60 | /** |
||
61 | * Observer update method |
||
62 | * Call obtainCurrentRoute method on action "apprun_loadAllAppModules". |
||
63 | * |
||
64 | * @param \SplSubject $subject |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | public function update(\SplSubject $subject) |
||
74 | |||
75 | /** |
||
76 | * Call by dispatcher; Add route in config to fastRoute router |
||
77 | * |
||
78 | * @param FastRoute\RouteCollector $router FastRoute router |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | public function addRoutesToCollector(FastRoute\RouteCollector $router) |
||
102 | |||
103 | /** |
||
104 | * Obtain informations about the current route from fastRoute dispatcher |
||
105 | * |
||
106 | * @return void |
||
107 | */ |
||
108 | public function obtainCurrentRoute() |
||
141 | |||
142 | /** |
||
143 | * Get http status for response from dispatcher |
||
144 | * |
||
145 | * @param int $routeStatus : Route status send by dispatcher for request |
||
146 | * |
||
147 | * @return int |
||
148 | */ |
||
149 | protected function checkStatus($routeStatus) |
||
161 | |||
162 | /** |
||
163 | * Obtains route informations from config file and send this informations |
||
164 | * to the controller/router linker |
||
165 | * |
||
166 | * @param array $routeInfos : Route information from config file |
||
167 | * |
||
168 | * @return void |
||
169 | * |
||
170 | * @throws \Exception If target not define in config file |
||
171 | */ |
||
172 | protected function sendInfosForRouteToLinker(array $routeInfos) |
||
180 | |||
181 | /** |
||
182 | * Add datas into a superglobal var |
||
183 | * |
||
184 | * @param string $globalVarName : Name of the superglobal var |
||
185 | * @param array $datasToAdd : Datas to add to $_GET var |
||
186 | * |
||
187 | * @return void |
||
188 | */ |
||
189 | protected function addToSuperglobalVar($globalVarName, array $datasToAdd) |
||
194 | |||
195 | /** |
||
196 | * If property 'get' has been declared into current route config, add |
||
197 | * them into superglobal $_GET . |
||
198 | * |
||
199 | * @param array $routeInfos route informations declared in config |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | protected function addDatasToGetAndPostVar(array $routeInfos) |
||
209 | |||
210 | /** |
||
211 | * Send to all observer of Application a notify who contains the message |
||
212 | * "request_route_find" to say the route for the current request has been |
||
213 | * found by us. |
||
214 | * |
||
215 | * @return void |
||
216 | */ |
||
217 | protected function sendNotifyRouteFindToOthers() |
||
222 | } |
||
223 |