1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mcorten87\rabbitmq_api\mappers; |
4
|
|
|
|
5
|
|
|
use mcorten87\rabbitmq_api\jobs\JobBase; |
6
|
|
|
use mcorten87\rabbitmq_api\jobs\JobExchangeDelete; |
7
|
|
|
use mcorten87\rabbitmq_api\jobs\JobExchangeList; |
8
|
|
|
use mcorten87\rabbitmq_api\jobs\JobExchangePublish; |
9
|
|
|
use mcorten87\rabbitmq_api\jobs\JobUserList; |
10
|
|
|
use mcorten87\rabbitmq_api\objects\Method; |
11
|
|
|
use mcorten87\rabbitmq_api\objects\Url; |
12
|
|
|
use mcorten87\rabbitmq_api\services\MqManagementConfig; |
13
|
|
|
|
14
|
|
|
class JobExchangePublishMapper extends BaseMapper |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
protected function mapMethod() : Method { |
18
|
|
|
return new Method(Method::METHOD_POST); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param JobExchangeDelete $job |
23
|
|
|
* @return Url |
24
|
|
|
*/ |
25
|
|
|
protected function mapUrl(JobBase $job) : Url { |
26
|
|
|
if (!$job instanceof JobExchangePublish) { |
27
|
|
|
throw new WrongArgumentException($job, JobExchangePublish::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$url = 'exchanges'; |
31
|
|
|
$url .= '/'.urlencode($job->getVirtualHost()); |
32
|
|
|
$url .= '/'.urlencode($job->getExchangeName()); |
33
|
|
|
$url .= '/publish'; |
34
|
|
|
return new Url($url); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param JobExchangePublish $job |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
protected function mapConfig(JobBase $job) : array { |
42
|
|
|
$body = [ |
43
|
|
|
'payload' => (string)$job->getMessage(), |
|
|
|
|
44
|
|
|
'payload_encoding' => 'string', // TODO |
45
|
|
|
'routing_key' => (string)$job->getRoutingKey(), |
|
|
|
|
46
|
|
|
'properties' => [ |
47
|
|
|
'delivery_mode' => (int)$job->getDeliveryMode(), |
|
|
|
|
48
|
|
|
'headers' => [] // TODO |
49
|
|
|
] |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
return array_merge(parent::mapConfig($job), [ |
53
|
|
|
'json' => $body, |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|