1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mcorten87\rabbitmq_api\mappers; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use mcorten87\rabbitmq_api\jobs\JobBase; |
7
|
|
|
use mcorten87\rabbitmq_api\jobs\JobBindingToExchangeCreate; |
8
|
|
|
use mcorten87\rabbitmq_api\objects\Method; |
9
|
|
|
use mcorten87\rabbitmq_api\objects\Url; |
10
|
|
|
use mcorten87\rabbitmq_api\services\MqManagementConfig; |
11
|
|
|
|
12
|
|
|
class JobBindingToExchangeDeleteMapper extends BaseMapper |
13
|
|
|
{ |
14
|
|
|
protected function mapMethod(JobBase $job) : Method |
15
|
|
|
{ |
16
|
|
|
return new Method(Method::METHOD_DELETE); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param JobBindingToExchangeCreate $job |
21
|
|
|
* @return Url |
22
|
|
|
*/ |
23
|
|
|
protected function mapUrl(JobBase $job) : Url |
24
|
|
|
{ |
25
|
|
|
return new Url('bindings/' |
26
|
|
|
.urlencode($job->getVirtualHost()).'/' |
|
|
|
|
27
|
|
|
.'e/' |
28
|
|
|
.urlencode($job->getExchangeName()).'/' |
|
|
|
|
29
|
|
|
.$job->getDestinationType().'/' |
|
|
|
|
30
|
|
|
.urlencode($job->getToExchange()) |
|
|
|
|
31
|
|
|
.'/'.(!empty((string) $job->getRoutingKey()) ? (string) $job->getRoutingKey() : '~') |
|
|
|
|
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param JobBindingToExchangeCreate $job |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
protected function mapConfig(JobBase $job) : array { |
40
|
|
|
$body = [ |
41
|
|
|
'destination' => (string)$job->getToExchange(), |
|
|
|
|
42
|
|
|
'destination_type' => $job->getDestinationType(), |
|
|
|
|
43
|
|
|
'properties_key' => (string)$job->getRoutingKey(), |
|
|
|
|
44
|
|
|
'source' => (string)$job->getExchangeName(), |
|
|
|
|
45
|
|
|
'vhost' => $job->getVirtualHost(), |
|
|
|
|
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
return array_merge(parent::mapConfig($job), [ |
49
|
|
|
'json' => $body, |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
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: