1 | <?php |
||
31 | final class ResourceDeleteSubscriber implements EventSubscriberInterface |
||
32 | { |
||
33 | /** |
||
34 | * @var UrlGeneratorInterface |
||
35 | */ |
||
36 | private $router; |
||
37 | |||
38 | /** |
||
39 | * @var SessionInterface |
||
40 | */ |
||
41 | private $session; |
||
42 | |||
43 | /** |
||
44 | * @var TranslatorInterface |
||
45 | */ |
||
46 | private $translator; |
||
47 | |||
48 | /** |
||
49 | * @var RestViewHandlerInterface |
||
50 | */ |
||
51 | private $viewHandler; |
||
52 | |||
53 | /** |
||
54 | * @param UrlGeneratorInterface $router |
||
55 | * @param SessionInterface $session |
||
56 | * @param TranslatorInterface $translator |
||
57 | * @param RestViewHandlerInterface $viewHandler |
||
58 | */ |
||
59 | public function __construct( |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public static function getSubscribedEvents() |
||
80 | |||
81 | /** |
||
82 | * @param GetResponseForExceptionEvent $event |
||
83 | */ |
||
84 | public function onResourceDelete(GetResponseForExceptionEvent $event) |
||
138 | |||
139 | /** |
||
140 | * @param string $route |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | private function getResourceNameFromRoute($route) |
||
152 | |||
153 | /** |
||
154 | * @param string $originalRoute |
||
155 | * @param string $targetAction |
||
156 | * |
||
157 | * @return RedirectResponse |
||
158 | */ |
||
159 | private function createRedirectResponse($originalRoute, $targetAction) |
||
165 | |||
166 | /** |
||
167 | * @param Request $request |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | private function isHtmlRequest(Request $request) |
||
175 | |||
176 | /** |
||
177 | * @param Request $request |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | private function isMethodDelete(Request $request) |
||
185 | |||
186 | /** |
||
187 | * @param string $route |
||
188 | * |
||
189 | * @return bool |
||
190 | */ |
||
191 | private function isSyliusRoute($route) |
||
195 | |||
196 | /** |
||
197 | * @param array $syliusParameters |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | private function isAdminSection(array $syliusParameters) |
||
205 | } |
||
206 |
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 implementation 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 interface: