|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace mcorten87\rabbitmq_api\mappers; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use mcorten87\rabbitmq_api\jobs\JobBase; |
|
7
|
|
|
use mcorten87\rabbitmq_api\jobs\JobBindingCreate; |
|
8
|
|
|
use mcorten87\rabbitmq_api\objects\Method; |
|
9
|
|
|
use mcorten87\rabbitmq_api\objects\Url; |
|
10
|
|
|
use mcorten87\rabbitmq_api\services\MqManagementConfig; |
|
11
|
|
|
|
|
12
|
|
|
class JoBindingCreateMapper extends BaseMapper |
|
13
|
|
|
{ |
|
14
|
|
|
protected function mapMethod(JobBase $job) : Method |
|
15
|
|
|
{ |
|
16
|
|
|
return new Method(Method::METHOD_POST); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param JobBindingCreate $job |
|
21
|
|
|
* @return Url |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function mapUrl(JobBase $job) : Url |
|
24
|
|
|
{ |
|
25
|
|
|
return new Url('bindings/' |
|
26
|
|
|
.urlencode($job->getVirtualHost()).'/' |
|
|
|
|
|
|
27
|
|
|
.urlencode($job->getQueueName()).'/' |
|
|
|
|
|
|
28
|
|
|
.urlencode($job->getExchangeName()).'/' |
|
|
|
|
|
|
29
|
|
|
.urlencode($job->getBindingName()) |
|
|
|
|
|
|
30
|
|
|
); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param JobBindingCreate $job |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function mapConfig(JobBase $job) : array { |
|
38
|
|
|
$body = [ |
|
39
|
|
|
'arguments' => [], |
|
40
|
|
|
'destination' => $job->getQueueName(), // TODO depends on destination_type |
|
|
|
|
|
|
41
|
|
|
'destination_type' => 'q', // TODO add exchange as destination |
|
42
|
|
|
'routing_key' => '', // TODO |
|
43
|
|
|
'source' => $job->getExchangeName(), |
|
|
|
|
|
|
44
|
|
|
'vhost' => $job->getVirtualHost(), |
|
|
|
|
|
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
foreach ($job->getArguments() as $argument) { |
|
|
|
|
|
|
48
|
|
|
$body['arguments'][$argument->getArgumentName()] = $argument->getValue(); |
|
49
|
|
|
}; |
|
50
|
|
|
|
|
51
|
|
|
return array_merge(parent::mapConfig($job), [ |
|
52
|
|
|
'json' => $body, |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
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: