1 | <?php |
||
15 | class BfwApi implements \SplObserver |
||
16 | { |
||
17 | /** |
||
18 | * @const ERR_RUN_CLASS_NOT_FOUND : Error code if the class to run has |
||
19 | * not been found |
||
20 | */ |
||
21 | const ERR_RUN_CLASS_NOT_FOUND = 2001001; |
||
22 | |||
23 | /** |
||
24 | * @const ERR_RUN_METHOD_NOT_FOUND : Error code if the method to run has |
||
25 | * not been found into the class |
||
26 | */ |
||
27 | const ERR_RUN_METHOD_NOT_FOUND = 2001002; |
||
28 | |||
29 | /** |
||
30 | * @const ERR_RUN_MODE_NOT_DECLARED : Error code if no mode (rest/graphQL) |
||
31 | * is declared into config file |
||
32 | */ |
||
33 | const ERR_RUN_MODE_NOT_DECLARED = 2001003; |
||
34 | |||
35 | /** |
||
36 | * @const ERR_CLASSNAME_NOT_DEFINE_FOR_URI : Error code if the class to use |
||
37 | * for current api route is not defined |
||
38 | */ |
||
39 | const ERR_CLASSNAME_NOT_DEFINE_FOR_URI = 2001004; |
||
40 | |||
41 | /** |
||
42 | * @const ERR_RUN_REST_NOT_IMPLEMENT_INTERFACE : The class used for the |
||
43 | * route in Rest mode not implement the interface |
||
44 | */ |
||
45 | const ERR_RUN_REST_NOT_IMPLEMENT_INTERFACE = 2001005; |
||
46 | |||
47 | /** |
||
48 | * @var \BFW\Module $module The bfw module instance for this module |
||
49 | */ |
||
50 | protected $module; |
||
51 | |||
52 | /** |
||
53 | * @var \BFW\Config $config The bfw config instance for this module |
||
54 | */ |
||
55 | protected $config; |
||
56 | |||
57 | /** |
||
58 | * @var \FastRoute\Dispatcher $dispatcher FastRoute dispatcher |
||
59 | */ |
||
60 | protected $dispatcher; |
||
61 | |||
62 | /** |
||
63 | * @var \stdClass|null $ctrlRouterInfos The context object passed to |
||
64 | * subject for the action "searchRoute". |
||
65 | */ |
||
66 | protected $ctrlRouterInfos; |
||
67 | |||
68 | /** |
||
69 | * @var string $execRouteSystemName The name of the current system. Used on |
||
70 | * event "execRoute". Allow to extends this class in another module :) |
||
71 | */ |
||
72 | protected $execRouteSystemName = 'bfw-api'; |
||
73 | |||
74 | /** |
||
75 | * Constructor |
||
76 | * |
||
77 | * @param \BFW\Module $module |
||
78 | */ |
||
79 | public function __construct(\BFW\Module $module) |
||
89 | |||
90 | /** |
||
91 | * Getter accessor for module property |
||
92 | * |
||
93 | * @return \BFW\Module |
||
94 | */ |
||
95 | public function getModule() |
||
99 | |||
100 | /** |
||
101 | * Getter accessor for config property |
||
102 | * |
||
103 | * @return \BFW\Config |
||
104 | */ |
||
105 | public function getConfig() |
||
109 | |||
110 | /** |
||
111 | * Getter accessor for dispatcher property |
||
112 | * |
||
113 | * @return \FastRoute\Dispatcher |
||
114 | */ |
||
115 | public function getDispatcher() |
||
119 | |||
120 | /** |
||
121 | * Getter accessor for ctrlRouterInfos property |
||
122 | * |
||
123 | * @return \stdClass |
||
124 | */ |
||
125 | public function getCtrlRouterInfos() |
||
129 | |||
130 | /** |
||
131 | * Getter accessor for execRouteSystemName property |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getExecRouteSystemName() |
||
139 | |||
140 | /** |
||
141 | * Call by dispatcher; Add route in config to fastRoute router |
||
142 | * |
||
143 | * @param \FastRoute\RouteCollector $router FastRoute router |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | public function addRoutesToCollector(\FastRoute\RouteCollector $router) |
||
170 | |||
171 | /** |
||
172 | * Observer update method |
||
173 | * |
||
174 | * @param \SplSubject $subject |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | public function update(\SplSubject $subject) |
||
204 | |||
205 | /** |
||
206 | * Set the property ctrlRouterInfos with the context object obtain linked |
||
207 | * to the subject. |
||
208 | * Allow override to get only some part. And used for unit test. |
||
209 | * |
||
210 | * @param \BFW\Subject $subject |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | protected function obtainCtrlRouterInfos($subject) |
||
218 | |||
219 | /** |
||
220 | * Obtain the classname to use for current route from fastRoute dispatcher |
||
221 | * |
||
222 | * @return void |
||
223 | * |
||
224 | * @throw \Exception If no "className" is define in config for the route. |
||
225 | */ |
||
226 | protected function searchRoute() |
||
277 | |||
278 | /** |
||
279 | * Get http status for response from dispatcher |
||
280 | * |
||
281 | * @param int $routeStatus : Route status send by dispatcher for request |
||
282 | * |
||
283 | * @return int |
||
284 | */ |
||
285 | protected function checkStatus($routeStatus) |
||
297 | |||
298 | /** |
||
299 | * |
||
300 | * |
||
301 | * @return void |
||
302 | */ |
||
303 | protected function execRoute() |
||
349 | |||
350 | /** |
||
351 | * Call the method for the current request for Rest api mode |
||
352 | * |
||
353 | * @param string $className The class name to use for the route |
||
354 | * @param string $method The method name to use (get/post/delete/put) |
||
355 | * |
||
356 | * @throws Exception If the interface is not implemented by the class |
||
357 | * |
||
358 | * @return void |
||
359 | */ |
||
360 | protected function runRest($className, $method) |
||
374 | |||
375 | /** |
||
376 | * Call the method for the current request for GraphQL api mode |
||
377 | * |
||
378 | * Not implemented yet |
||
379 | */ |
||
380 | protected function runGraphQL() |
||
387 | } |
||
388 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: