1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mouf\Utils\Mailer; |
4
|
|
|
|
5
|
|
|
use Mouf\Html\HtmlElement\HtmlElementInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This class represents a mail to be sent using a Mailer class extending the MailerInterface. |
9
|
|
|
* + it has special features to add a text mail for any HTML mail that has not been provided the text mail. |
10
|
|
|
* |
11
|
|
|
* Note: default encoding for the mail is UTF-8 if not specified. |
12
|
|
|
* |
13
|
|
|
* @Component |
14
|
|
|
*/ |
15
|
|
|
class Mail implements MailInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $bodyText; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var HtmlElementInterface |
24
|
|
|
*/ |
25
|
|
|
protected $bodyHtml; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var HtmlElementInterface |
29
|
|
|
*/ |
30
|
|
|
protected $title; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var MailAddressInterface |
34
|
|
|
*/ |
35
|
|
|
protected $from; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var MailAddressInterface[] |
39
|
|
|
*/ |
40
|
|
|
protected $toRecipients = array(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var MailAddressInterface[] |
44
|
|
|
*/ |
45
|
|
|
protected $ccRecipients = array(); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var MailAddressInterface[] |
49
|
|
|
*/ |
50
|
|
|
protected $bccRecipients = array(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var MailAttachmentInterface[] |
54
|
|
|
*/ |
55
|
|
|
protected $attachements = array(); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $encoding = 'utf-8'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var bool |
64
|
|
|
*/ |
65
|
|
|
protected $autocreateMissingText = true; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
protected $css; |
71
|
|
|
|
72
|
|
|
public function __construct(string $title, string $bodyText = null) |
73
|
|
|
{ |
74
|
|
|
$this->title = $title; |
|
|
|
|
75
|
|
|
$this->bodyText = $bodyText; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the mail text body. |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getBodyText() :string |
84
|
|
|
{ |
85
|
|
|
return $this->bodyText; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The mail text body. |
90
|
|
|
* |
91
|
|
|
* @Property |
92
|
|
|
* |
93
|
|
|
* @param string $bodyText |
94
|
|
|
*/ |
|
|
|
|
95
|
|
|
public function setBodyText(string $bodyText) :string |
96
|
|
|
{ |
97
|
|
|
$this->bodyText = $bodyText; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the mail html body. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getBodyHtml():string |
106
|
|
|
{ |
107
|
|
|
return $this->bodyHtml->getHtml(); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The mail html body. |
112
|
|
|
* |
113
|
|
|
* @param HtmlElementInterface $bodyHtml |
114
|
|
|
*/ |
115
|
|
|
public function setBodyHtml(HtmlElementInterface $bodyHtml) |
116
|
|
|
{ |
117
|
|
|
$this->bodyHtml = $bodyHtml; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the mail title. |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getTitle():string |
126
|
|
|
{ |
127
|
|
|
return $this->title->getHtml(); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* The mail title. |
132
|
|
|
* |
133
|
|
|
* @param string $title |
134
|
|
|
*/ |
135
|
|
|
public function setTitle(HtmlElementInterface $title) |
136
|
|
|
{ |
137
|
|
|
$this->title = $title; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns the "From" email address. |
142
|
|
|
* |
143
|
|
|
* @return MailAddressInterface The first element is the email address, the second the name to display. |
144
|
|
|
*/ |
145
|
|
|
public function getFrom():MailAddressInterface |
146
|
|
|
{ |
147
|
|
|
return $this->from; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* The mail from address. |
152
|
|
|
* |
153
|
|
|
* @param MailAddressInterface $from |
154
|
|
|
*/ |
155
|
|
|
public function setFrom(MailAddressInterface $from) |
156
|
|
|
{ |
157
|
|
|
$this->from = $from; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Returns an array containing the recipients. |
162
|
|
|
* |
163
|
|
|
* @return MailAddressInterface[] |
164
|
|
|
*/ |
165
|
|
|
public function getToRecipients(): array |
166
|
|
|
{ |
167
|
|
|
return $this->toRecipients; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* An array containing the recipients. |
172
|
|
|
* |
173
|
|
|
* @param MailAddressInterface[] $toRecipients |
174
|
|
|
*/ |
175
|
|
|
public function setToRecipients(array $toRecipients) |
176
|
|
|
{ |
177
|
|
|
$this->toRecipients = $toRecipients; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Adss a recipient. |
182
|
|
|
* |
183
|
|
|
* @param MailAddressInterface $toRecipient |
184
|
|
|
*/ |
185
|
|
|
public function addToRecipient(MailAddressInterface $toRecipient) |
186
|
|
|
{ |
187
|
|
|
$this->toRecipients[] = $toRecipient; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Returns an array containing the recipients in Cc. |
192
|
|
|
* |
193
|
|
|
* @return MailAddressInterface[] |
194
|
|
|
*/ |
195
|
|
|
public function getCcRecipients(): array |
196
|
|
|
{ |
197
|
|
|
return $this->ccRecipients; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* An array containing the recipients. |
202
|
|
|
* |
203
|
|
|
* |
204
|
|
|
* @param MailAddressInterface[]$ccRecipients |
205
|
|
|
*/ |
206
|
|
|
public function setCcRecipients(array $ccRecipients) |
207
|
|
|
{ |
208
|
|
|
$this->ccRecipients = $ccRecipients; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Adds a recipient. |
213
|
|
|
* |
214
|
|
|
* @param MailAddressInterface $ccRecipient |
215
|
|
|
*/ |
216
|
|
|
public function addCcRecipient(MailAddressInterface $ccRecipient) |
217
|
|
|
{ |
218
|
|
|
$this->ccRecipients[] = $ccRecipient; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Returns an array containing the recipients in Bcc. |
223
|
|
|
* |
224
|
|
|
* @return MailAddressInterface[] |
225
|
|
|
*/ |
226
|
|
|
public function getBccRecipients():array |
227
|
|
|
{ |
228
|
|
|
return $this->bccRecipients; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* An array containing the recipients. |
233
|
|
|
* |
234
|
|
|
* @param MailAddressInterface[] $bccRecipients |
235
|
|
|
*/ |
236
|
|
|
public function setBccRecipients(array $bccRecipients) |
237
|
|
|
{ |
238
|
|
|
$this->bccRecipients = $bccRecipients; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Adds a recipient. |
243
|
|
|
* |
244
|
|
|
* @param MailAddressInterface $bccRecipient |
245
|
|
|
*/ |
246
|
|
|
public function addBccRecipient(MailAddressInterface $bccRecipient) |
247
|
|
|
{ |
248
|
|
|
$this->bccRecipients[] = $bccRecipient; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Returns an array of attachements for that mail. |
253
|
|
|
* |
254
|
|
|
* @return MailAttachmentInterface[] |
255
|
|
|
*/ |
256
|
|
|
public function getAttachements():array |
257
|
|
|
{ |
258
|
|
|
return $this->attachements; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* An array containing the attachments. |
263
|
|
|
* |
264
|
|
|
* @param array<MailAttachmentInterface> $attachements |
265
|
|
|
*/ |
266
|
|
|
public function setAttachements(array $attachements) |
267
|
|
|
{ |
268
|
|
|
$this->attachements = $attachements; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Adds an attachment. |
273
|
|
|
* |
274
|
|
|
* @param MailAttachmentInterface $attachement |
275
|
|
|
*/ |
276
|
|
|
public function addAttachement(MailAttachmentInterface $attachement) |
277
|
|
|
{ |
278
|
|
|
$this->attachements[] = $attachement; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Returns the encoding of the mail. |
283
|
|
|
* |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
|
|
public function getEncoding():string |
287
|
|
|
{ |
288
|
|
|
return $this->encoding; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* The mail encoding. Defaults to utf-8. |
293
|
|
|
* |
294
|
|
|
* @param string $encoding |
295
|
|
|
*/ |
296
|
|
|
public function setEncoding($encoding) |
297
|
|
|
{ |
298
|
|
|
$this->encoding = $encoding; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
} |
302
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..