1 | <?php |
||
30 | class EventStatusLinkResponseListener |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * @var ProducerInterface Producer for publishing messages. |
||
35 | */ |
||
36 | private $rabbitMqProducer = null; |
||
37 | |||
38 | /** |
||
39 | * @var RouterInterface Router to generate resource URLs |
||
40 | */ |
||
41 | private $router = null; |
||
42 | |||
43 | /** |
||
44 | * @var Request request |
||
45 | */ |
||
46 | private $request; |
||
47 | |||
48 | /** |
||
49 | * @var QueueEvent queue event document |
||
50 | */ |
||
51 | private $queueEventDocument; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private $eventMap; |
||
57 | |||
58 | /** |
||
59 | * @var ExtReferenceConverter ExtReferenceConverter |
||
60 | */ |
||
61 | private $extRefConverter; |
||
62 | |||
63 | /** |
||
64 | * @var string classname of the EventWorker document |
||
65 | */ |
||
66 | private $eventWorkerClassname; |
||
67 | |||
68 | /** |
||
69 | * @var string classname of the EventStatus document |
||
70 | */ |
||
71 | private $eventStatusClassname; |
||
72 | |||
73 | /** |
||
74 | * @var string classname of the EventStatusStatus document |
||
75 | */ |
||
76 | private $eventStatusStatusClassname; |
||
77 | |||
78 | /** |
||
79 | * @var string classname of the EventStatusEventResource document |
||
80 | */ |
||
81 | private $eventStatusEventResourceClassname; |
||
82 | |||
83 | /** |
||
84 | * @var string route name of the /event/status route |
||
85 | */ |
||
86 | private $eventStatusRouteName; |
||
87 | |||
88 | /** |
||
89 | * @var DocumentManager Document manager |
||
90 | */ |
||
91 | private $documentManager; |
||
92 | |||
93 | /** |
||
94 | * @var SecurityUtils |
||
95 | */ |
||
96 | protected $securityUtils; |
||
97 | |||
98 | /** |
||
99 | * @var Uri |
||
100 | */ |
||
101 | protected $workerRelativeUrl; |
||
102 | |||
103 | /** |
||
104 | * @param ProducerInterface $rabbitMqProducer RabbitMQ dependency |
||
105 | * @param RouterInterface $router Router dependency |
||
106 | * @param RequestStack $requestStack Request stack |
||
107 | * @param DocumentManager $documentManager Doctrine document manager |
||
108 | * @param ExtReferenceConverter $extRefConverter instance of the ExtReferenceConverter service |
||
109 | * @param QueueEvent $queueEventDocument queueevent document |
||
110 | * @param array $eventMap eventmap |
||
111 | * @param string $eventWorkerClassname classname of the EventWorker document |
||
112 | * @param string $eventStatusClassname classname of the EventStatus document |
||
113 | * @param string $eventStatusStatusClassname classname of the EventStatusStatus document |
||
114 | * @param string $eventStatusEventResourceClassname classname of the E*S*E*Resource document |
||
115 | * @param string $eventStatusRouteName name of the route to EventStatus |
||
116 | * @param SecurityUtils $securityUtils Security utils service |
||
117 | * @param string $workerRelativeUrl backend url relative from the workers |
||
118 | */ |
||
119 | 2 | public function __construct( |
|
152 | |||
153 | /** |
||
154 | * add a rel=eventStatus Link header to the response if necessary |
||
155 | * |
||
156 | * @param FilterResponseEvent $event response listener event |
||
157 | * |
||
158 | * @return void |
||
159 | */ |
||
160 | 2 | public function onKernelResponse(FilterResponseEvent $event) |
|
207 | |||
208 | /** |
||
209 | * we only want to do something if we have a mapped event.. |
||
210 | * |
||
211 | * @return boolean true if it should not concern us, false otherwise |
||
212 | */ |
||
213 | 2 | private function isNotConcerningRequest() |
|
217 | |||
218 | /** |
||
219 | * Creates the structured object that will be sent to the queue (eventually..) |
||
220 | * |
||
221 | * @return QueueEvent event |
||
222 | */ |
||
223 | 2 | private function createQueueEventObject() |
|
233 | |||
234 | /** |
||
235 | * compose our routingKey. this will have the form of 'document.[bundle].[document].[event]' |
||
236 | * rules: |
||
237 | * * always 4 parts divided by points. |
||
238 | * * in this context (doctrine/odm stuff) we prefix with 'document.' |
||
239 | * |
||
240 | * @return string routing key |
||
241 | */ |
||
242 | 2 | private function generateRoutingKey() |
|
262 | |||
263 | /** |
||
264 | * Creates a EventStatus object that gets persisted.. |
||
265 | * |
||
266 | * @param QueueEvent $queueEvent queueEvent object |
||
267 | * |
||
268 | * @return string |
||
269 | */ |
||
270 | 2 | private function getStatusUrl($queueEvent) |
|
316 | |||
317 | /** |
||
318 | * Checks EventWorker for worker that are subscribed to our event and returns |
||
319 | * their workerIds as array |
||
320 | |||
321 | * @param QueueEvent $queueEvent queueEvent object |
||
322 | * |
||
323 | * @return array array of worker ids |
||
324 | */ |
||
325 | 2 | private function getSubscribedWorkerIds(QueueEvent $queueEvent) |
|
355 | |||
356 | /** |
||
357 | * Security needs to be enabled to get |
||
358 | * |
||
359 | * @return String |
||
360 | */ |
||
361 | 2 | private function getSecurityUsername() |
|
369 | |||
370 | /** |
||
371 | * Changes the urls in the QueueEvent for the workers |
||
372 | * |
||
373 | * @param QueueEvent $queueEvent queue event |
||
374 | * |
||
375 | * @return QueueEvent altered queue event |
||
376 | */ |
||
377 | private function getWorkerQueueEvent(QueueEvent $queueEvent) |
||
383 | |||
384 | /** |
||
385 | * changes an uri for the workers |
||
386 | * |
||
387 | * @param string $uri uri |
||
388 | * |
||
389 | * @return string changed uri |
||
390 | */ |
||
391 | private function getWorkerRelativeUrl($uri) |
||
400 | } |
||
401 |
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: