1 | <?php |
||
15 | class BfwApi implements \SplObserver |
||
16 | { |
||
17 | /** |
||
18 | * @var \BFW\Module $module The bfw module instance for this module |
||
19 | */ |
||
20 | protected $module; |
||
21 | |||
22 | /** |
||
23 | * @var \BFW\Config $config The bfw config instance for this module |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | /** |
||
28 | * @var \FastRoute\Dispatcher $dispatcher FastRoute dispatcher |
||
29 | */ |
||
30 | protected $dispatcher; |
||
31 | |||
32 | /** |
||
33 | * @var boolean $routeFindByOther If the route for current request has been |
||
34 | * found by an other module. So we not need to search. |
||
35 | */ |
||
36 | protected $routeFindByOther; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param \BFW\Module $module |
||
42 | */ |
||
43 | public function __construct(\BFW\Module $module) |
||
52 | |||
53 | /** |
||
54 | * Call by dispatcher; Add route in config to fastRoute router |
||
55 | * |
||
56 | * @param \FastRoute\RouteCollector $router FastRoute router |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function addRoutesToCollector(\FastRoute\RouteCollector $router) |
||
81 | |||
82 | /** |
||
83 | * Observer update method |
||
84 | * Call run method on action "bfw_run_finish" and route has |
||
85 | * not been already found. |
||
86 | * Update attribute routeFindByOther on action "request_route_find". |
||
87 | * |
||
88 | * @param \SplSubject $subject |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | public function update(\SplSubject $subject) |
||
105 | |||
106 | /** |
||
107 | * Run when the notify "bfw_run_finish" is emit |
||
108 | * Check if we are in an API route |
||
109 | * If it's an API route, |
||
110 | * * Get the class name to use for this route |
||
111 | * * Call the method corresponding to request in the class declared |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | public function run() |
||
145 | |||
146 | protected function runRest($className, $method) |
||
151 | |||
152 | protected function runGraphQL() |
||
157 | |||
158 | /** |
||
159 | * Obtain the classname to use for current route from fastRoute dispatcher |
||
160 | * |
||
161 | * @return string|void The classname or nothing if error |
||
162 | * |
||
163 | * @throw \Exception If no "className" is define in config for the route. |
||
164 | */ |
||
165 | protected function obtainClassNameForCurrentRoute() |
||
196 | |||
197 | /** |
||
198 | * Get http status for response from dispatcher |
||
199 | * |
||
200 | * @param int $routeStatus : Route status send by dispatcher for request |
||
201 | * |
||
202 | * @return int |
||
203 | */ |
||
204 | protected function checkStatus($routeStatus) |
||
216 | |||
217 | /** |
||
218 | * Send to all observer of Application a notify who contains the message |
||
219 | * "request_route_find" to say the route for the current request has been |
||
220 | * found by us. |
||
221 | * |
||
222 | * @return void |
||
223 | */ |
||
224 | protected function sendNotifyRouteFindToOthers() |
||
229 | } |
||
230 |