1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2013-2016 Mailgun |
5
|
|
|
* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Mailgun\Model\Event; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Tobias Nyholm <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Event |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string status |
19
|
|
|
*/ |
20
|
|
|
private $event; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var float |
29
|
|
|
*/ |
30
|
|
|
private $timestamp; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* A \DateTime representation of $timestamp. |
34
|
|
|
* |
35
|
|
|
* @var \DateTime |
36
|
|
|
*/ |
37
|
|
|
private $eventDate; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array|string[] |
41
|
|
|
*/ |
42
|
|
|
private $tags = []; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $url; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $severity; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
private $envelope = []; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
private $deliveryStatus; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var array|string[] |
66
|
|
|
*/ |
67
|
|
|
private $campaigns = []; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
private $ip; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var array |
76
|
|
|
*/ |
77
|
|
|
private $clientInfo = []; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $reason; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var array |
86
|
|
|
*/ |
87
|
|
|
private $userVariables = []; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var array key=>bool |
91
|
|
|
*/ |
92
|
|
|
private $flags = []; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var array multi dimensions |
96
|
|
|
*/ |
97
|
|
|
private $routes = []; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var array multi dimensions |
101
|
|
|
*/ |
102
|
|
|
private $message = []; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var string |
106
|
|
|
*/ |
107
|
|
|
private $recipient; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var array |
111
|
|
|
*/ |
112
|
|
|
private $geolocation = []; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var array |
116
|
|
|
*/ |
117
|
|
|
private $storage = []; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var string |
121
|
|
|
*/ |
122
|
|
|
private $method; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $event |
126
|
|
|
* @param string $id |
127
|
|
|
* @param float $timestamp |
128
|
|
|
*/ |
129
|
|
|
public function __construct($event, $id, $timestamp) |
130
|
|
|
{ |
131
|
|
|
$this->event = $event; |
132
|
|
|
$this->id = $id; |
133
|
|
|
$this->timestamp = $timestamp; |
134
|
|
|
$this->eventDate = new \DateTime(); |
135
|
|
|
$this->eventDate->setTimestamp((int) $timestamp); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param array $data |
140
|
|
|
* |
141
|
|
|
* @return Event |
142
|
|
|
*/ |
143
|
|
|
public static function create(array $data) |
144
|
|
|
{ |
145
|
|
|
$event = new self($data['event'], $data['id'], $data['timestamp']); |
146
|
|
|
|
147
|
|
|
if (isset($data['tags'])) { |
148
|
|
|
$event->setTags($data['tags']); |
149
|
|
|
} |
150
|
|
|
if (isset($data['envelope'])) { |
151
|
|
|
$event->setEnvelope($data['envelope']); |
152
|
|
|
} |
153
|
|
|
if (isset($data['campaigns'])) { |
154
|
|
|
$event->setCampaigns($data['campaigns']); |
155
|
|
|
} |
156
|
|
|
if (isset($data['user-variables'])) { |
157
|
|
|
$event->setUserVariables($data['user-variables']); |
158
|
|
|
} |
159
|
|
|
if (isset($data['flags'])) { |
160
|
|
|
$event->setFlags($data['flags']); |
161
|
|
|
} |
162
|
|
|
if (isset($data['routes'])) { |
163
|
|
|
$event->setRoutes($data['routes']); |
164
|
|
|
} |
165
|
|
|
if (isset($data['message'])) { |
166
|
|
|
$event->setMessage($data['message']); |
167
|
|
|
} |
168
|
|
|
if (isset($data['recipient'])) { |
169
|
|
|
$event->setRecipient($data['recipient']); |
170
|
|
|
} |
171
|
|
|
if (isset($data['method'])) { |
172
|
|
|
$event->setMethod($data['method']); |
173
|
|
|
} |
174
|
|
|
if (isset($data['delivery-status'])) { |
175
|
|
|
$event->setDeliveryStatus($data['delivery-status']); |
176
|
|
|
} |
177
|
|
|
if (isset($data['severity'])) { |
178
|
|
|
$event->setSeverity($data['severity']); |
179
|
|
|
} |
180
|
|
|
if (isset($data['reason'])) { |
181
|
|
|
$event->setReason($data['reason']); |
182
|
|
|
} |
183
|
|
|
if (isset($data['geolocation'])) { |
184
|
|
|
$event->setGeolocation($data['geolocation']); |
185
|
|
|
} |
186
|
|
|
if (isset($data['ip'])) { |
187
|
|
|
$event->setIp($data['ip']); |
188
|
|
|
} |
189
|
|
|
if (isset($data['client-info'])) { |
190
|
|
|
$event->setClientInfo($data['client-info']); |
191
|
|
|
} |
192
|
|
|
if (isset($data['url'])) { |
193
|
|
|
$event->setUrl($data['url']); |
194
|
|
|
} |
195
|
|
|
if (isset($data['storage'])) { |
196
|
|
|
$event->setStorage($data['storage']); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return $event; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function getEvent() |
206
|
|
|
{ |
207
|
|
|
return $this->event; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
|
|
public function getId() |
214
|
|
|
{ |
215
|
|
|
return $this->id; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return float |
220
|
|
|
*/ |
221
|
|
|
public function getTimestamp() |
222
|
|
|
{ |
223
|
|
|
return $this->timestamp; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return \DateTime |
228
|
|
|
*/ |
229
|
|
|
public function getEventDate() |
230
|
|
|
{ |
231
|
|
|
return $this->eventDate; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return array|\string[] |
236
|
|
|
*/ |
237
|
|
|
public function getTags() |
238
|
|
|
{ |
239
|
|
|
return $this->tags; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param array|\string[] $tags |
244
|
|
|
*/ |
245
|
|
|
private function setTags($tags) |
246
|
|
|
{ |
247
|
|
|
$this->tags = $tags; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
|
|
public function getUrl() |
254
|
|
|
{ |
255
|
|
|
return $this->url; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param string $url |
260
|
|
|
*/ |
261
|
|
|
private function setUrl($url) |
262
|
|
|
{ |
263
|
|
|
$this->url = $url; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return array |
268
|
|
|
*/ |
269
|
|
|
public function getEnvelope() |
270
|
|
|
{ |
271
|
|
|
return $this->envelope; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param array $envelope |
276
|
|
|
*/ |
277
|
|
|
private function setEnvelope($envelope) |
278
|
|
|
{ |
279
|
|
|
$this->envelope = $envelope; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return array |
284
|
|
|
*/ |
285
|
|
|
public function getDeliveryStatus() |
286
|
|
|
{ |
287
|
|
|
return $this->deliveryStatus; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param array $deliveryStatus |
292
|
|
|
*/ |
293
|
|
|
private function setDeliveryStatus($deliveryStatus) |
294
|
|
|
{ |
295
|
|
|
$this->deliveryStatus = $deliveryStatus; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return array|\string[] |
300
|
|
|
*/ |
301
|
|
|
public function getCampaigns() |
302
|
|
|
{ |
303
|
|
|
return $this->campaigns; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param array|\string[] $campaigns |
308
|
|
|
*/ |
309
|
|
|
private function setCampaigns($campaigns) |
310
|
|
|
{ |
311
|
|
|
$this->campaigns = $campaigns; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @return string |
316
|
|
|
*/ |
317
|
|
|
public function getIp() |
318
|
|
|
{ |
319
|
|
|
return $this->ip; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @param string $ip |
324
|
|
|
*/ |
325
|
|
|
private function setIp($ip) |
326
|
|
|
{ |
327
|
|
|
$this->ip = $ip; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return array |
332
|
|
|
*/ |
333
|
|
|
public function getClientInfo() |
334
|
|
|
{ |
335
|
|
|
return $this->clientInfo; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param array $clientInfo |
340
|
|
|
*/ |
341
|
|
|
private function setClientInfo($clientInfo) |
342
|
|
|
{ |
343
|
|
|
$this->clientInfo = $clientInfo; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
|
|
public function getReason() |
350
|
|
|
{ |
351
|
|
|
return $this->reason; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @param string $reason |
356
|
|
|
*/ |
357
|
|
|
private function setReason($reason) |
358
|
|
|
{ |
359
|
|
|
$this->reason = $reason; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @return array |
364
|
|
|
*/ |
365
|
|
|
public function getUserVariables() |
366
|
|
|
{ |
367
|
|
|
return $this->userVariables; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @param array $userVariables |
372
|
|
|
*/ |
373
|
|
|
private function setUserVariables($userVariables) |
374
|
|
|
{ |
375
|
|
|
$this->userVariables = $userVariables; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @return array |
380
|
|
|
*/ |
381
|
|
|
public function getFlags() |
382
|
|
|
{ |
383
|
|
|
return $this->flags; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @param array $flags |
388
|
|
|
*/ |
389
|
|
|
private function setFlags($flags) |
390
|
|
|
{ |
391
|
|
|
$this->flags = $flags; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @return array |
396
|
|
|
*/ |
397
|
|
|
public function getRoutes() |
398
|
|
|
{ |
399
|
|
|
return $this->routes; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @param array $routes |
404
|
|
|
*/ |
405
|
|
|
private function setRoutes($routes) |
406
|
|
|
{ |
407
|
|
|
$this->routes = $routes; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @return array |
412
|
|
|
*/ |
413
|
|
|
public function getMessage() |
414
|
|
|
{ |
415
|
|
|
return $this->message; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @param array $message |
420
|
|
|
*/ |
421
|
|
|
private function setMessage($message) |
422
|
|
|
{ |
423
|
|
|
$this->message = $message; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @return string |
428
|
|
|
*/ |
429
|
|
|
public function getRecipient() |
430
|
|
|
{ |
431
|
|
|
return $this->recipient; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @param string $recipient |
436
|
|
|
*/ |
437
|
|
|
private function setRecipient($recipient) |
438
|
|
|
{ |
439
|
|
|
$this->recipient = $recipient; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return array |
444
|
|
|
*/ |
445
|
|
|
public function getGeolocation() |
446
|
|
|
{ |
447
|
|
|
return $this->geolocation; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @param array $geolocation |
452
|
|
|
*/ |
453
|
|
|
private function setGeolocation($geolocation) |
454
|
|
|
{ |
455
|
|
|
$this->geolocation = $geolocation; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return array |
460
|
|
|
*/ |
461
|
|
|
public function getStorage() |
462
|
|
|
{ |
463
|
|
|
return $this->storage; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @param array $storage |
468
|
|
|
*/ |
469
|
|
|
private function setStorage($storage) |
470
|
|
|
{ |
471
|
|
|
$this->storage = $storage; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* @return string |
476
|
|
|
*/ |
477
|
|
|
public function getMethod() |
478
|
|
|
{ |
479
|
|
|
return $this->method; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* @param string $method |
484
|
|
|
*/ |
485
|
|
|
private function setMethod($method) |
486
|
|
|
{ |
487
|
|
|
$this->method = $method; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* @return string |
492
|
|
|
*/ |
493
|
|
|
public function getSeverity() |
494
|
|
|
{ |
495
|
|
|
return $this->severity; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* @param string $severity |
500
|
|
|
*/ |
501
|
|
|
private function setSeverity($severity) |
502
|
|
|
{ |
503
|
|
|
$this->severity = $severity; |
504
|
|
|
} |
505
|
|
|
} |
506
|
|
|
|