1 | <?php |
||
10 | class Notification |
||
11 | { |
||
12 | /** |
||
13 | * @var null|NotificationId |
||
14 | */ |
||
15 | protected $notificationId; |
||
16 | |||
17 | /** |
||
18 | * @var Destination |
||
19 | */ |
||
20 | protected $destination; |
||
21 | |||
22 | /** |
||
23 | * @var Subject |
||
24 | */ |
||
25 | protected $subject; |
||
26 | |||
27 | /** |
||
28 | * @var Body |
||
29 | */ |
||
30 | protected $body; |
||
31 | |||
32 | /** |
||
33 | * @var null|DeduplicationKey |
||
34 | */ |
||
35 | protected $deduplicationKey; |
||
36 | |||
37 | /** |
||
38 | * @var null|string |
||
39 | */ |
||
40 | protected $templateName; |
||
41 | |||
42 | /** |
||
43 | * @var array|null |
||
44 | */ |
||
45 | protected $templateVariables; |
||
46 | |||
47 | /** |
||
48 | * @var DateTimeImmutable |
||
49 | */ |
||
50 | protected $createdAt; |
||
51 | |||
52 | /** |
||
53 | * @var null|DateTimeImmutable |
||
54 | */ |
||
55 | protected $sentAt; |
||
56 | |||
57 | /** |
||
58 | * @var null|DateTimeImmutable |
||
59 | */ |
||
60 | protected $failedAt; |
||
61 | |||
62 | /** |
||
63 | * @var null|string |
||
64 | */ |
||
65 | protected $failedFor; |
||
66 | |||
67 | /** |
||
68 | * @param Destination $destination |
||
69 | * @param Subject $subject |
||
70 | * @param Body $body |
||
71 | * @param DeduplicationKey|null $deduplicationKey |
||
72 | * @param string|null $templateName |
||
73 | * @param array|null $templateVariables |
||
74 | */ |
||
75 | 13 | public function __construct( |
|
76 | Destination $destination, |
||
77 | Subject $subject, |
||
78 | Body $body, |
||
79 | DeduplicationKey $deduplicationKey = null, |
||
80 | string $templateName = null, |
||
81 | array $templateVariables = null |
||
82 | ) { |
||
83 | 13 | $this->destination = $destination; |
|
84 | 13 | $this->subject = $subject; |
|
85 | 13 | $this->body = $body; |
|
86 | 13 | $this->deduplicationKey = $deduplicationKey; |
|
87 | 13 | $this->templateName = $templateName; |
|
88 | 13 | $this->templateVariables = $templateVariables; |
|
89 | 13 | $this->createdAt = new DateTimeImmutable; |
|
90 | 13 | $this->sentAt = null; |
|
91 | 13 | $this->failedAt = null; |
|
92 | 13 | $this->failedFor = null; |
|
93 | 13 | } |
|
94 | |||
95 | /** |
||
96 | * @return null|NotificationId |
||
97 | */ |
||
98 | 3 | public function notificationId(): ?NotificationId |
|
99 | { |
||
100 | 3 | return $this->notificationId; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return Destination |
||
105 | */ |
||
106 | 9 | public function destination(): Destination |
|
107 | { |
||
108 | 9 | return $this->destination; |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return Subject |
||
113 | */ |
||
114 | 5 | public function subject(): Subject |
|
115 | { |
||
116 | 5 | return $this->subject; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return Body |
||
121 | */ |
||
122 | 4 | public function body(): Body |
|
123 | { |
||
124 | 4 | return $this->body; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return null|DeduplicationKey |
||
129 | */ |
||
130 | 5 | public function deduplicationKey(): ?DeduplicationKey |
|
131 | { |
||
132 | 5 | return $this->deduplicationKey; |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return DateTimeImmutable |
||
137 | */ |
||
138 | 2 | public function createdAt(): DateTimeImmutable |
|
139 | { |
||
140 | 2 | return $this->createdAt; |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return DateTimeImmutable|null |
||
145 | */ |
||
146 | 6 | public function sentAt(): ?DateTimeImmutable |
|
147 | { |
||
148 | 6 | return $this->sentAt; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return bool |
||
153 | */ |
||
154 | 6 | public function isSent(): bool |
|
158 | |||
159 | /** |
||
160 | * @return void |
||
161 | */ |
||
162 | 4 | public function markSent(): void |
|
163 | { |
||
164 | 4 | $this->assertNotSent(); |
|
165 | 4 | $this->unmarkFailed(); |
|
166 | 4 | $this->sentAt = new DateTimeImmutable; |
|
168 | |||
169 | /** |
||
170 | * @return DateTimeImmutable|null |
||
171 | */ |
||
172 | 3 | public function failedAt(): ?DateTimeImmutable |
|
176 | |||
177 | /** |
||
178 | * @return null|string |
||
179 | */ |
||
180 | 2 | public function failedFor(): ?string |
|
184 | |||
185 | /** |
||
186 | * @return bool |
||
187 | */ |
||
188 | 3 | public function isFailed(): bool |
|
192 | |||
193 | /** |
||
194 | * @return void |
||
195 | */ |
||
196 | 3 | public function markFailed(string $reason): void |
|
202 | |||
203 | /** |
||
204 | * @return void |
||
205 | */ |
||
206 | 4 | public function unmarkFailed(): void |
|
211 | |||
212 | /** |
||
213 | * @return bool |
||
214 | */ |
||
215 | 1 | public function isFresh(): bool |
|
219 | |||
220 | /** |
||
221 | * @return void |
||
222 | */ |
||
223 | 6 | private function assertNotSent(): void |
|
235 | |||
236 | /** |
||
237 | * For InMemoryNotificationRepository only. |
||
238 | * |
||
239 | * @param NotificationId $notificationId |
||
240 | */ |
||
241 | 2 | public function setNotificationId(NotificationId $notificationId): void |
|
245 | } |
||
246 | |||
247 |