1 | <?php |
||
28 | class EventStatusLinkResponseListener |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * @var ProducerInterface Producer for publishing messages. |
||
33 | */ |
||
34 | private $rabbitMqProducer = null; |
||
35 | |||
36 | /** |
||
37 | * @var RouterInterface Router to generate resource URLs |
||
38 | */ |
||
39 | private $router = null; |
||
40 | |||
41 | /** |
||
42 | * @var Request request |
||
43 | */ |
||
44 | private $request; |
||
45 | |||
46 | /** |
||
47 | * @var QueueEvent queue event document |
||
48 | */ |
||
49 | private $queueEventDocument; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | private $eventMap; |
||
55 | |||
56 | /** |
||
57 | * @var ExtReferenceConverter ExtReferenceConverter |
||
58 | */ |
||
59 | private $extRefConverter; |
||
60 | |||
61 | /** |
||
62 | * @var string classname of the EventWorker document |
||
63 | */ |
||
64 | private $eventWorkerClassname; |
||
65 | |||
66 | /** |
||
67 | * @var string classname of the EventStatus document |
||
68 | */ |
||
69 | private $eventStatusClassname; |
||
70 | |||
71 | /** |
||
72 | * @var string classname of the EventStatusStatus document |
||
73 | */ |
||
74 | private $eventStatusStatusClassname; |
||
75 | |||
76 | /** |
||
77 | * @var string classname of the EventStatusEventResource document |
||
78 | */ |
||
79 | private $eventStatusEventResourceClassname; |
||
80 | |||
81 | /** |
||
82 | * @var string route name of the /event/status route |
||
83 | */ |
||
84 | private $eventStatusRouteName; |
||
85 | |||
86 | /** |
||
87 | * @var DocumentManager Document manager |
||
88 | */ |
||
89 | private $documentManager; |
||
90 | |||
91 | /** |
||
92 | * @var SecurityUtils |
||
93 | */ |
||
94 | protected $securityUtils; |
||
95 | |||
96 | /** |
||
97 | * @param ProducerInterface $rabbitMqProducer RabbitMQ dependency |
||
98 | * @param RouterInterface $router Router dependency |
||
99 | * @param RequestStack $requestStack Request stack |
||
100 | * @param DocumentManager $documentManager Doctrine document manager |
||
101 | * @param ExtReferenceConverter $extRefConverter instance of the ExtReferenceConverter service |
||
102 | * @param QueueEvent $queueEventDocument queueevent document |
||
103 | * @param array $eventMap eventmap |
||
104 | * @param string $eventWorkerClassname classname of the EventWorker document |
||
105 | * @param string $eventStatusClassname classname of the EventStatus document |
||
106 | * @param string $eventStatusStatusClassname classname of the EventStatusStatus document |
||
107 | * @param string $eventStatusEventResourceClassname classname of the E*S*E*Resource document |
||
108 | * @param string $eventStatusRouteName name of the route to EventStatus |
||
109 | * @param SecurityUtils $securityUtils Security utils service |
||
110 | */ |
||
111 | public function __construct( |
||
140 | |||
141 | /** |
||
142 | * add a rel=eventStatus Link header to the response if necessary |
||
143 | * |
||
144 | * @param FilterResponseEvent $event response listener event |
||
145 | * |
||
146 | * @return void |
||
147 | */ |
||
148 | public function onKernelResponse(FilterResponseEvent $event) |
||
189 | |||
190 | /** |
||
191 | * we only want to do something if we have a mapped event.. |
||
192 | * |
||
193 | * @return boolean true if it should not concern us, false otherwise |
||
194 | */ |
||
195 | private function isNotConcerningRequest() |
||
199 | |||
200 | /** |
||
201 | * Creates the structured object that will be sent to the queue (eventually..) |
||
202 | * |
||
203 | * @return QueueEvent event |
||
204 | */ |
||
205 | private function createQueueEventObject() |
||
215 | |||
216 | /** |
||
217 | * compose our routingKey. this will have the form of 'document.[bundle].[document].[event]' |
||
218 | * rules: |
||
219 | * * always 4 parts divided by points. |
||
220 | * * in this context (doctrine/odm stuff) we prefix with 'document.' |
||
221 | * |
||
222 | * @return string routing key |
||
223 | */ |
||
224 | private function generateRoutingKey() |
||
244 | |||
245 | /** |
||
246 | * Creates a EventStatus object that gets persisted.. |
||
247 | * |
||
248 | * @param QueueEvent $queueEvent queueEvent object |
||
249 | * |
||
250 | * @return string |
||
251 | */ |
||
252 | private function getStatusUrl($queueEvent) |
||
298 | |||
299 | /** |
||
300 | * Checks EventWorker for worker that are subscribed to our event and returns |
||
301 | * their workerIds as array |
||
302 | |||
303 | * @param QueueEvent $queueEvent queueEvent object |
||
304 | * |
||
305 | * @return array array of worker ids |
||
306 | */ |
||
307 | private function getSubscribedWorkerIds(QueueEvent $queueEvent) |
||
337 | |||
338 | /** |
||
339 | * Security needs to be enabled to get |
||
340 | * |
||
341 | * @return String |
||
342 | */ |
||
343 | private function getSecurityUsername() |
||
351 | } |
||
352 |
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: