|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TreeHouse\Queue\Message; |
|
4
|
|
|
|
|
5
|
|
|
class Message |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var string |
|
9
|
|
|
*/ |
|
10
|
|
|
private $id; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
private $body; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var MessageProperties |
|
19
|
|
|
*/ |
|
20
|
|
|
private $properties; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $routingKey; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $id |
|
29
|
|
|
* @param string $body |
|
30
|
|
|
* @param MessageProperties|null $properties |
|
31
|
|
|
* @param string|null $routingKey |
|
32
|
|
|
*/ |
|
33
|
18 |
|
public function __construct($body, MessageProperties $properties = null, $id = null, $routingKey = null) |
|
34
|
|
|
{ |
|
35
|
18 |
|
$this->id = $id; |
|
36
|
18 |
|
$this->body = $body; |
|
37
|
18 |
|
$this->properties = $properties ?: new MessageProperties(); |
|
38
|
18 |
|
$this->routingKey = $routingKey; |
|
39
|
18 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Resets id and deep-clones properties. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __clone() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->id = null; |
|
47
|
|
|
$this->properties = new MessageProperties($this->properties->toArray()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function getId() |
|
54
|
|
|
{ |
|
55
|
4 |
|
return $this->id; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $body |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function setBody($body) |
|
62
|
|
|
{ |
|
63
|
1 |
|
$this->body = $body; |
|
64
|
1 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
12 |
|
public function getBody() |
|
70
|
|
|
{ |
|
71
|
12 |
|
return $this->body; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param MessageProperties $properties |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function setProperties($properties) |
|
78
|
|
|
{ |
|
79
|
1 |
|
$this->properties = $properties; |
|
80
|
1 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return MessageProperties |
|
84
|
|
|
*/ |
|
85
|
7 |
|
public function getProperties() |
|
86
|
|
|
{ |
|
87
|
7 |
|
return $this->properties; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $routingKey |
|
92
|
|
|
*/ |
|
93
|
2 |
|
public function setRoutingKey($routingKey) |
|
94
|
|
|
{ |
|
95
|
2 |
|
$this->routingKey = $routingKey; |
|
96
|
2 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
8 |
|
public function getRoutingKey() |
|
102
|
|
|
{ |
|
103
|
8 |
|
return $this->routingKey; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param string $contentType |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function setContentType($contentType) |
|
110
|
|
|
{ |
|
111
|
1 |
|
$this->properties->set(MessageProperties::KEY_CONTENT_TYPE, $contentType); |
|
112
|
1 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
2 |
|
public function getContentType() |
|
118
|
|
|
{ |
|
119
|
2 |
|
return $this->properties->get(MessageProperties::KEY_CONTENT_TYPE); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param int $deliveryMode |
|
124
|
|
|
*/ |
|
125
|
1 |
|
public function setDeliveryMode($deliveryMode) |
|
126
|
|
|
{ |
|
127
|
1 |
|
$this->properties->set(MessageProperties::KEY_DELIVERY_MODE, (integer) $deliveryMode); |
|
128
|
1 |
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return int |
|
132
|
|
|
*/ |
|
133
|
2 |
|
public function getDeliveryMode() |
|
134
|
|
|
{ |
|
135
|
2 |
|
return $this->properties->get(MessageProperties::KEY_DELIVERY_MODE); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param int $priority |
|
140
|
|
|
*/ |
|
141
|
8 |
|
public function setPriority($priority) |
|
142
|
|
|
{ |
|
143
|
8 |
|
$this->properties->set(MessageProperties::KEY_PRIORITY, (integer) $priority); |
|
144
|
8 |
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return int |
|
148
|
|
|
*/ |
|
149
|
3 |
|
public function getPriority() |
|
150
|
|
|
{ |
|
151
|
3 |
|
return $this->properties->get(MessageProperties::KEY_PRIORITY); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param int $timestamp |
|
156
|
|
|
*/ |
|
157
|
|
|
public function setTimestamp($timestamp) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->properties->set(MessageProperties::KEY_TIMESTAMP, (integer) $timestamp); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return int |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getTimestamp() |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->properties->get(MessageProperties::KEY_TIMESTAMP); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param string $name |
|
172
|
|
|
* @param mixed $value |
|
173
|
|
|
*/ |
|
174
|
2 |
|
public function setHeader($name, $value) |
|
175
|
|
|
{ |
|
176
|
2 |
|
$headers = $this->getHeaders(); |
|
177
|
2 |
|
$headers[$name] = $value; |
|
178
|
|
|
|
|
179
|
2 |
|
$this->properties[MessageProperties::KEY_HEADERS] = $headers; |
|
180
|
2 |
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Get a specific message header. |
|
184
|
|
|
* |
|
185
|
|
|
* @param string $name Name of the header to get the value from. |
|
186
|
|
|
* |
|
187
|
|
|
* @return string|bool The contents of the specified header or false if not set. |
|
188
|
|
|
*/ |
|
189
|
3 |
|
public function getHeader($name) |
|
190
|
|
|
{ |
|
191
|
3 |
|
$headers = $this->getHeaders(); |
|
192
|
|
|
|
|
193
|
3 |
|
if (!isset($headers[$name])) { |
|
194
|
1 |
|
return false; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
3 |
|
return $headers[$name]; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Get the headers of the message. |
|
202
|
|
|
* |
|
203
|
|
|
* @return array An array of key value pairs associated with the message. |
|
204
|
|
|
*/ |
|
205
|
4 |
|
public function getHeaders() |
|
206
|
|
|
{ |
|
207
|
4 |
|
if (!isset($this->properties[MessageProperties::KEY_HEADERS])) { |
|
208
|
2 |
|
$this->properties[MessageProperties::KEY_HEADERS] = []; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
4 |
|
return $this->properties[MessageProperties::KEY_HEADERS]; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|