1 | <?php |
||
26 | class MainController |
||
27 | { |
||
28 | /** |
||
29 | * @var Router |
||
30 | */ |
||
31 | private $router; |
||
32 | |||
33 | /** |
||
34 | * @var Response |
||
35 | */ |
||
36 | private $response; |
||
37 | |||
38 | /** |
||
39 | * @var RestUtilsInterface |
||
40 | */ |
||
41 | private $restUtils; |
||
42 | |||
43 | /** |
||
44 | * @var EventDispatcherInterface |
||
45 | */ |
||
46 | private $eventDispatcher; |
||
47 | |||
48 | /** |
||
49 | * @var ApiDefinitionLoader |
||
50 | */ |
||
51 | private $apiLoader; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private $addditionalRoutes; |
||
57 | |||
58 | /** |
||
59 | * @var array |
||
60 | */ |
||
61 | private $pathWhitelist; |
||
62 | |||
63 | /** |
||
64 | * @var array |
||
65 | */ |
||
66 | private $proxySourceConfiguration; |
||
67 | |||
68 | /** |
||
69 | * @param Router $router router |
||
70 | * @param Response $response prepared response |
||
71 | * @param RestUtilsInterface $restUtils rest-utils from GravitonRestBundle |
||
72 | * @param EventDispatcherInterface $eventDispatcher event dispatcher |
||
73 | * @param ApiDefinitionLoader $apiLoader loader for third party api definition |
||
74 | * @param array $additionalRoutes custom routes |
||
75 | * @param array $pathWhitelist serviec path that always get aded to the main page |
||
76 | * @param array $proxySourceConfiguration Set of sources to be recognized by the controller |
||
77 | */ |
||
78 | public function __construct( |
||
97 | |||
98 | /** |
||
99 | * create simple start page. |
||
100 | * |
||
101 | * @return Response $response Response with result or error |
||
102 | */ |
||
103 | public function indexAction() |
||
124 | |||
125 | /** |
||
126 | * Determines what service endpoints are available. |
||
127 | * |
||
128 | * @param array $optionRoutes List of routing options. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | protected function determineServices(array $optionRoutes) |
||
173 | |||
174 | /** |
||
175 | * gets the additional routes that can be injected by listeners/subscribers |
||
176 | * |
||
177 | * @param array $sortArr array needed for sorting |
||
178 | * |
||
179 | * @return array additional routes |
||
180 | */ |
||
181 | private function getAdditionalRoutes(array &$sortArr) |
||
202 | |||
203 | /** |
||
204 | * Prepares the header field containing information about pagination. |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function prepareLinkHeader() |
||
220 | |||
221 | /** |
||
222 | * tells if a service is relevant for the mainpage |
||
223 | * |
||
224 | * @param array $val value of service spec |
||
225 | * |
||
226 | * @return boolean |
||
227 | */ |
||
228 | private function isRelevantForMainPage($val) |
||
233 | |||
234 | /** |
||
235 | * Resolves all third party routes and add schema info |
||
236 | * |
||
237 | * @param array $thirdApiRoutes list of all routes from an API |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | protected function determineThirdPartyServices(array $thirdApiRoutes) |
||
262 | |||
263 | /** |
||
264 | * Finds configured external apis to be exposed via G2. |
||
265 | * |
||
266 | * @return array |
||
267 | */ |
||
268 | private function registerThirdPartyServices() |
||
288 | |||
289 | /** |
||
290 | * get API name and endpoint from the url (third party API) |
||
291 | * |
||
292 | * @param array $config Configuration information ['prefix', 'serviceEndpoint'] |
||
293 | * |
||
294 | * @return array |
||
295 | */ |
||
296 | protected function decideApiAndEndpoint(array $config) |
||
307 | |||
308 | /** |
||
309 | * Return OPTIONS results. |
||
310 | * |
||
311 | * @param Request $request Current http request |
||
312 | * |
||
313 | * @return Response $response Result of the action |
||
314 | */ |
||
315 | public function optionsAction(Request $request) |
||
323 | } |
||
324 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: