1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Burrow; |
4
|
|
|
|
5
|
|
|
use Assert\Assertion; |
6
|
|
|
|
7
|
|
|
class Message |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
private $body; |
11
|
|
|
|
12
|
|
|
/** @var string */ |
13
|
|
|
private $routingKey; |
14
|
|
|
|
15
|
|
|
/** @var string[] */ |
16
|
|
|
private $headers; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
private $correlationId; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private $replyTo; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $queue; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
private $deliveryTag; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Message constructor. |
32
|
|
|
* |
33
|
|
|
* @param string $body |
34
|
|
|
* @param string $routingKey |
35
|
|
|
* @param \string[] $headers |
36
|
|
|
* @param string $correlationId |
37
|
|
|
* @param string $replyTo |
38
|
|
|
*/ |
39
|
|
|
public function __construct($body, $routingKey = '', array $headers = [], $correlationId = '', $replyTo = '') |
40
|
|
|
{ |
41
|
|
|
Assertion::string($body, 'Message body must be a string'); |
42
|
|
|
Assertion::String($routingKey, 'Routing key must be a string'); |
43
|
|
|
Assertion::String($correlationId, 'Correlation ID must be a string'); |
44
|
|
|
Assertion::String($replyTo, 'Reply To must be a string'); |
45
|
|
|
|
46
|
|
|
$this->checkHeaders($headers); |
47
|
|
|
|
48
|
|
|
$this->body = $body; |
49
|
|
|
$this->routingKey = $routingKey; |
50
|
|
|
$this->headers = $headers; |
|
|
|
|
51
|
|
|
$this->correlationId = $correlationId; |
52
|
|
|
$this->replyTo = $replyTo; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $deliveryTag |
57
|
|
|
*/ |
58
|
|
|
public function setDeliveryTag($deliveryTag) |
59
|
|
|
{ |
60
|
|
|
$this->deliveryTag = $deliveryTag; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $queue |
65
|
|
|
*/ |
66
|
|
|
public function setQueue($queue) |
67
|
|
|
{ |
68
|
|
|
$this->queue = $queue; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getBody() |
75
|
|
|
{ |
76
|
|
|
return $this->body; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getRoutingKey() |
83
|
|
|
{ |
84
|
|
|
return $this->routingKey; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function getHeaders() |
91
|
|
|
{ |
92
|
|
|
return $this->headers; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getCorrelationId() |
99
|
|
|
{ |
100
|
|
|
return $this->correlationId; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getReplyTo() |
107
|
|
|
{ |
108
|
|
|
return $this->replyTo; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getDeliveryTag() |
115
|
|
|
{ |
116
|
|
|
return $this->deliveryTag; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getQueue() |
123
|
|
|
{ |
124
|
|
|
return $this->queue; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string[] $headers |
129
|
|
|
*/ |
130
|
|
|
private function checkHeaders(array $headers) |
131
|
|
|
{ |
132
|
|
|
foreach ($headers as $key => $value) { |
133
|
|
|
Assertion::string($key, 'Header key must be a string'); |
134
|
|
|
Assertion::notBlank($key, 'Header key must be a non empty string'); |
135
|
|
|
Assertion::notNull($value, 'Value cannot be null'); |
136
|
|
|
|
137
|
|
|
if (!is_string($value) && |
138
|
|
|
!is_numeric($value) && |
139
|
|
|
!is_bool($value) |
140
|
|
|
) { |
141
|
|
|
throw new \InvalidArgumentException('Value must be a string, a number or a boolean.'); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..