1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (C) 2013 Mailgun |
7
|
|
|
* |
8
|
|
|
* This software may be modified and distributed under the terms |
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mailgun\Model\Event; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Tobias Nyholm <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
final class Event |
18
|
|
|
{ |
19
|
|
|
private $event; |
20
|
|
|
private $id; |
21
|
|
|
private $timestamp; |
22
|
|
|
private $eventDate; |
23
|
|
|
private $tags; |
24
|
|
|
private $url; |
25
|
|
|
private $severity; |
26
|
|
|
private $envelope; |
27
|
|
|
private $deliveryStatus; |
28
|
|
|
private $campaigns; |
29
|
|
|
private $ip; |
30
|
|
|
private $clientInfo; |
31
|
|
|
private $reason; |
32
|
|
|
private $userVariables; |
33
|
|
|
private $flags; |
34
|
|
|
private $routes; |
35
|
|
|
private $message; |
36
|
|
|
private $recipient; |
37
|
|
|
private $geolocation; |
38
|
|
|
private $storage; |
39
|
|
|
private $method; |
40
|
|
|
|
41
|
2 |
|
private function __construct() |
42
|
|
|
{ |
43
|
2 |
|
} |
44
|
|
|
|
45
|
2 |
|
public static function create(array $data): self |
46
|
|
|
{ |
47
|
2 |
|
$model = new self(); |
48
|
2 |
|
$model->event = $data['event']; |
49
|
2 |
|
$model->id = $data['id']; |
50
|
2 |
|
$model->timestamp = (int) $data['timestamp']; |
51
|
2 |
|
$model->eventDate = (new \DateTimeImmutable())->setTimestamp((int) $data['timestamp']); |
52
|
2 |
|
$model->tags = $data['tags'] ?? []; |
53
|
2 |
|
$model->envelope = $data['envelope'] ?? []; |
54
|
2 |
|
$model->campaigns = $data['campaigns'] ?? []; |
55
|
2 |
|
$model->userVariables = $data['user-variables'] ?? []; |
56
|
2 |
|
$model->flags = $data['flags'] ?? []; |
57
|
2 |
|
$model->routes = $data['routes'] ?? []; |
58
|
2 |
|
$model->message = $data['message'] ?? []; |
59
|
2 |
|
$model->recipient = $data['recipient'] ?? ''; |
60
|
2 |
|
$model->method = $data['method'] ?? ''; |
61
|
2 |
|
$model->deliveryStatus = $data['delivery-status'] ?? []; |
62
|
2 |
|
$model->severity = $data['severity'] ?? ''; |
63
|
2 |
|
$model->reason = $data['reason'] ?? ''; |
64
|
2 |
|
$model->geolocation = $data['geolocation'] ?? []; |
65
|
2 |
|
$model->ip = $data['ip'] ?? ''; |
66
|
2 |
|
$model->clientInfo = $data['client-info'] ?? []; |
67
|
2 |
|
$model->url = $data['url'] ?? ''; |
68
|
2 |
|
$model->storage = $data['storage'] ?? []; |
69
|
|
|
|
70
|
2 |
|
return $model; |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
public function getEvent(): string |
74
|
|
|
{ |
75
|
1 |
|
return $this->event; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
public function getId(): string |
79
|
|
|
{ |
80
|
1 |
|
return $this->id; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getTimestamp(): int |
84
|
|
|
{ |
85
|
|
|
return $this->timestamp; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* A \DateTimeImmutable representation of $timestamp. |
90
|
|
|
*/ |
91
|
|
|
public function getEventDate(): \DateTimeImmutable |
92
|
|
|
{ |
93
|
|
|
return $this->eventDate; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string[] |
98
|
|
|
*/ |
99
|
|
|
public function getTags(): array |
100
|
|
|
{ |
101
|
|
|
return $this->tags; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getUrl(): string |
105
|
|
|
{ |
106
|
|
|
return $this->url; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getSeverity(): string |
110
|
|
|
{ |
111
|
|
|
return $this->severity; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getEnvelope(): array |
115
|
|
|
{ |
116
|
|
|
return $this->envelope; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getDeliveryStatus(): array |
120
|
|
|
{ |
121
|
|
|
return $this->deliveryStatus; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string[] |
126
|
|
|
*/ |
127
|
|
|
public function getCampaigns(): array |
128
|
|
|
{ |
129
|
|
|
return $this->campaigns; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getIp(): string |
133
|
|
|
{ |
134
|
|
|
return $this->ip; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getClientInfo(): array |
138
|
|
|
{ |
139
|
|
|
return $this->clientInfo; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getReason(): string |
143
|
|
|
{ |
144
|
|
|
return $this->reason; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getUserVariables(): array |
148
|
|
|
{ |
149
|
|
|
return $this->userVariables; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* key=>bool. |
154
|
|
|
*/ |
155
|
|
|
public function getFlags(): array |
156
|
|
|
{ |
157
|
|
|
return $this->flags; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* multi dimensions. |
162
|
|
|
*/ |
163
|
|
|
public function getRoutes(): array |
164
|
|
|
{ |
165
|
|
|
return $this->routes; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* multi dimensions. |
170
|
|
|
*/ |
171
|
|
|
public function getMessage(): array |
172
|
|
|
{ |
173
|
|
|
return $this->message; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function getRecipient(): string |
177
|
|
|
{ |
178
|
|
|
return $this->recipient; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function getGeolocation(): array |
182
|
|
|
{ |
183
|
|
|
return $this->geolocation; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function getStorage(): array |
187
|
|
|
{ |
188
|
|
|
return $this->storage; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function getMethod(): string |
192
|
|
|
{ |
193
|
|
|
return $this->method; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|