|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Model\Basic\Message; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\AMQP\Model\Basic\Message; |
|
7
|
|
|
use Innmind\TimeContinuum\{ |
|
8
|
|
|
PointInTimeInterface, |
|
9
|
|
|
ElapsedPeriod, |
|
10
|
|
|
}; |
|
11
|
|
|
use Innmind\Immutable\{ |
|
12
|
|
|
MapInterface, |
|
13
|
|
|
Map, |
|
14
|
|
|
Str, |
|
15
|
|
|
}; |
|
16
|
|
|
use function Innmind\Immutable\assertMap; |
|
17
|
|
|
|
|
18
|
|
|
final class Generic implements Message |
|
19
|
|
|
{ |
|
20
|
|
|
private $contentType; |
|
21
|
|
|
private $contentEncoding; |
|
22
|
|
|
private $headers; |
|
23
|
|
|
private $deliveryMode; |
|
24
|
|
|
private $priority; |
|
25
|
|
|
private $correlationId; |
|
26
|
|
|
private $replyTo; |
|
27
|
|
|
private $expiration; |
|
28
|
|
|
private $id; |
|
29
|
|
|
private $timestamp; |
|
30
|
|
|
private $type; |
|
31
|
|
|
private $userId; |
|
32
|
|
|
private $appId; |
|
33
|
|
|
private $body; |
|
34
|
|
|
|
|
35
|
68 |
|
public function __construct(Str $body) |
|
36
|
|
|
{ |
|
37
|
68 |
|
$this->body = $body->toEncoding('ASCII'); |
|
38
|
68 |
|
$this->headers = new Map('string', 'mixed'); |
|
39
|
68 |
|
} |
|
40
|
|
|
|
|
41
|
30 |
|
public function hasContentType(): bool |
|
42
|
|
|
{ |
|
43
|
30 |
|
return $this->contentType instanceof ContentType; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
6 |
|
public function contentType(): ContentType |
|
47
|
|
|
{ |
|
48
|
6 |
|
return $this->contentType; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
6 |
|
public function withContentType(ContentType $contentType): Message |
|
52
|
|
|
{ |
|
53
|
6 |
|
$self = clone $this; |
|
54
|
6 |
|
$self->contentType = $contentType; |
|
55
|
|
|
|
|
56
|
6 |
|
return $self; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
30 |
|
public function hasContentEncoding(): bool |
|
60
|
|
|
{ |
|
61
|
30 |
|
return $this->contentEncoding instanceof ContentEncoding; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
6 |
|
public function contentEncoding(): ContentEncoding |
|
65
|
|
|
{ |
|
66
|
6 |
|
return $this->contentEncoding; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
6 |
|
public function withContentEncoding(ContentEncoding $contentEncoding): Message |
|
70
|
|
|
{ |
|
71
|
6 |
|
$self = clone $this; |
|
72
|
6 |
|
$self->contentEncoding = $contentEncoding; |
|
73
|
|
|
|
|
74
|
6 |
|
return $self; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
30 |
|
public function hasHeaders(): bool |
|
78
|
|
|
{ |
|
79
|
30 |
|
return $this->headers->size() > 0; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
7 |
|
public function headers(): MapInterface |
|
86
|
|
|
{ |
|
87
|
7 |
|
return $this->headers; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
7 |
|
public function withHeaders(MapInterface $headers): Message |
|
91
|
|
|
{ |
|
92
|
7 |
|
assertMap('string', 'mixed', $headers, 1); |
|
93
|
|
|
|
|
94
|
6 |
|
$self = clone $this; |
|
95
|
6 |
|
$self->headers = $headers; |
|
96
|
|
|
|
|
97
|
6 |
|
return $self; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
30 |
|
public function hasDeliveryMode(): bool |
|
101
|
|
|
{ |
|
102
|
30 |
|
return $this->deliveryMode instanceof DeliveryMode; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
6 |
|
public function deliveryMode(): DeliveryMode |
|
106
|
|
|
{ |
|
107
|
6 |
|
return $this->deliveryMode; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
6 |
|
public function withDeliveryMode(DeliveryMode $deliveryMode): Message |
|
111
|
|
|
{ |
|
112
|
6 |
|
$self = clone $this; |
|
113
|
6 |
|
$self->deliveryMode = $deliveryMode; |
|
114
|
|
|
|
|
115
|
6 |
|
return $self; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
30 |
|
public function hasPriority(): bool |
|
119
|
|
|
{ |
|
120
|
30 |
|
return $this->priority instanceof Priority; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
6 |
|
public function priority(): Priority |
|
124
|
|
|
{ |
|
125
|
6 |
|
return $this->priority; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
6 |
|
public function withPriority(Priority $priority): Message |
|
129
|
|
|
{ |
|
130
|
6 |
|
$self = clone $this; |
|
131
|
6 |
|
$self->priority = $priority; |
|
132
|
|
|
|
|
133
|
6 |
|
return $self; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
30 |
|
public function hasCorrelationId(): bool |
|
137
|
|
|
{ |
|
138
|
30 |
|
return $this->correlationId instanceof CorrelationId; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
6 |
|
public function correlationId(): CorrelationId |
|
142
|
|
|
{ |
|
143
|
6 |
|
return $this->correlationId; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
6 |
|
public function withCorrelationId(CorrelationId $correlationId): Message |
|
147
|
|
|
{ |
|
148
|
6 |
|
$self = clone $this; |
|
149
|
6 |
|
$self->correlationId = $correlationId; |
|
150
|
|
|
|
|
151
|
6 |
|
return $self; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
30 |
|
public function hasReplyTo(): bool |
|
155
|
|
|
{ |
|
156
|
30 |
|
return $this->replyTo instanceof ReplyTo; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
6 |
|
public function replyTo(): ReplyTo |
|
160
|
|
|
{ |
|
161
|
6 |
|
return $this->replyTo; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
6 |
|
public function withReplyTo(ReplyTo $replyTo): Message |
|
165
|
|
|
{ |
|
166
|
6 |
|
$self = clone $this; |
|
167
|
6 |
|
$self->replyTo = $replyTo; |
|
168
|
|
|
|
|
169
|
6 |
|
return $self; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
30 |
|
public function hasExpiration(): bool |
|
173
|
|
|
{ |
|
174
|
30 |
|
return $this->expiration instanceof ElapsedPeriod; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
6 |
|
public function expiration(): ElapsedPeriod |
|
178
|
|
|
{ |
|
179
|
6 |
|
return $this->expiration; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
6 |
|
public function withExpiration(ElapsedPeriod $expiration): Message |
|
183
|
|
|
{ |
|
184
|
6 |
|
$self = clone $this; |
|
185
|
6 |
|
$self->expiration = $expiration; |
|
186
|
|
|
|
|
187
|
6 |
|
return $self; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
30 |
|
public function hasId(): bool |
|
191
|
|
|
{ |
|
192
|
30 |
|
return $this->id instanceof Id; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
6 |
|
public function id(): Id |
|
196
|
|
|
{ |
|
197
|
6 |
|
return $this->id; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
6 |
|
public function withId(Id $id): Message |
|
201
|
|
|
{ |
|
202
|
6 |
|
$self = clone $this; |
|
203
|
6 |
|
$self->id = $id; |
|
204
|
|
|
|
|
205
|
6 |
|
return $self; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
30 |
|
public function hasTimestamp(): bool |
|
209
|
|
|
{ |
|
210
|
30 |
|
return $this->timestamp instanceof PointInTimeInterface; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
6 |
|
public function timestamp(): PointInTimeInterface |
|
214
|
|
|
{ |
|
215
|
6 |
|
return $this->timestamp; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
6 |
|
public function withTimestamp(PointInTimeInterface $timestamp): Message |
|
219
|
|
|
{ |
|
220
|
6 |
|
$self = clone $this; |
|
221
|
6 |
|
$self->timestamp = $timestamp; |
|
222
|
|
|
|
|
223
|
6 |
|
return $self; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
30 |
|
public function hasType(): bool |
|
227
|
|
|
{ |
|
228
|
30 |
|
return $this->type instanceof Type; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
6 |
|
public function type(): Type |
|
232
|
|
|
{ |
|
233
|
6 |
|
return $this->type; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
6 |
|
public function withType(Type $type): Message |
|
237
|
|
|
{ |
|
238
|
6 |
|
$self = clone $this; |
|
239
|
6 |
|
$self->type = $type; |
|
240
|
|
|
|
|
241
|
6 |
|
return $self; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
30 |
|
public function hasUserId(): bool |
|
245
|
|
|
{ |
|
246
|
30 |
|
return $this->userId instanceof UserId; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
6 |
|
public function userId(): UserId |
|
250
|
|
|
{ |
|
251
|
6 |
|
return $this->userId; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
6 |
|
public function withUserId(UserId $userId): Message |
|
255
|
|
|
{ |
|
256
|
6 |
|
$self = clone $this; |
|
257
|
6 |
|
$self->userId = $userId; |
|
258
|
|
|
|
|
259
|
6 |
|
return $self; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
30 |
|
public function hasAppId(): bool |
|
263
|
|
|
{ |
|
264
|
30 |
|
return $this->appId instanceof AppId; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
6 |
|
public function appId(): AppId |
|
268
|
|
|
{ |
|
269
|
6 |
|
return $this->appId; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
6 |
|
public function withAppId(AppId $appId): Message |
|
273
|
|
|
{ |
|
274
|
6 |
|
$self = clone $this; |
|
275
|
6 |
|
$self->appId = $appId; |
|
276
|
|
|
|
|
277
|
6 |
|
return $self; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
28 |
|
public function body(): Str |
|
281
|
|
|
{ |
|
282
|
28 |
|
return $this->body; |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|