1
|
|
|
<?php |
2
|
|
|
namespace AcMailer\Options; |
3
|
|
|
|
4
|
|
|
use AcMailer\Exception\InvalidArgumentException; |
5
|
|
|
use Zend\Stdlib\AbstractOptions; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class MessageOptions |
9
|
|
|
* @author Alejandro Celaya Alastrué |
10
|
|
|
* @link http://www.alejandrocelaya.com |
11
|
|
|
*/ |
12
|
|
|
class MessageOptions extends AbstractOptions |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $from = ''; |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $fromName = ''; |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $replyTo = ''; |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $replyToName = ''; |
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $to = []; |
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $cc = []; |
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $bcc = []; |
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $subject = ''; |
46
|
|
|
/** |
47
|
|
|
* @var BodyOptions |
48
|
|
|
*/ |
49
|
|
|
protected $body; |
50
|
|
|
/** |
51
|
|
|
* @var AttachmentsOptions |
52
|
|
|
*/ |
53
|
|
|
protected $attachments; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
18 |
|
public function getFrom() |
59
|
|
|
{ |
60
|
18 |
|
return $this->from; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $from |
65
|
|
|
* @return $this |
66
|
|
|
*/ |
67
|
6 |
|
public function setFrom($from) |
68
|
|
|
{ |
69
|
6 |
|
$this->from = $from; |
70
|
6 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
2 |
|
public function getFromName() |
77
|
|
|
{ |
78
|
2 |
|
return $this->fromName; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $fromName |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
1 |
|
public function setFromName($fromName) |
86
|
|
|
{ |
87
|
1 |
|
$this->fromName = $fromName; |
88
|
1 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
14 |
|
public function getReplyTo() |
95
|
|
|
{ |
96
|
14 |
|
return $this->replyTo; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $replyTo |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
1 |
|
public function setReplyTo($replyTo) |
104
|
|
|
{ |
105
|
1 |
|
$this->replyTo = $replyTo; |
106
|
|
|
|
107
|
1 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
2 |
|
public function getReplyToName() |
114
|
|
|
{ |
115
|
2 |
|
return $this->replyToName; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $replyToName |
120
|
|
|
* @return $this |
121
|
|
|
*/ |
122
|
1 |
|
public function setReplyToName($replyToName) |
123
|
|
|
{ |
124
|
1 |
|
$this->replyToName = $replyToName; |
125
|
|
|
|
126
|
1 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
18 |
|
public function getTo() |
133
|
|
|
{ |
134
|
18 |
|
return $this->to; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param array|string $to |
139
|
|
|
* @return $this |
140
|
|
|
*/ |
141
|
6 |
|
public function setTo($to) |
142
|
|
|
{ |
143
|
6 |
|
$this->to = (array) $to; |
144
|
6 |
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
15 |
|
public function getCc() |
151
|
|
|
{ |
152
|
15 |
|
return $this->cc; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param array|string $cc |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
1 |
|
public function setCc($cc) |
160
|
|
|
{ |
161
|
1 |
|
$this->cc = (array) $cc; |
162
|
1 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return array |
167
|
|
|
*/ |
168
|
15 |
|
public function getBcc() |
169
|
|
|
{ |
170
|
15 |
|
return $this->bcc; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param string|array $bcc |
175
|
|
|
* @return $this |
176
|
|
|
*/ |
177
|
1 |
|
public function setBcc($bcc) |
178
|
|
|
{ |
179
|
1 |
|
$this->bcc = (array) $bcc; |
180
|
1 |
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
13 |
|
public function getSubject() |
187
|
|
|
{ |
188
|
13 |
|
return $this->subject; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param string $subject |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
2 |
|
public function setSubject($subject) |
196
|
|
|
{ |
197
|
2 |
|
$this->subject = $subject; |
198
|
2 |
|
return $this; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return BodyOptions |
203
|
|
|
*/ |
204
|
13 |
|
public function getBody() |
205
|
|
|
{ |
206
|
13 |
|
if (! isset($this->body)) { |
207
|
9 |
|
$this->setBody([]); |
208
|
9 |
|
} |
209
|
|
|
|
210
|
13 |
|
return $this->body; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param BodyOptions|array $body |
215
|
|
|
* @return $this |
216
|
|
|
*/ |
217
|
14 |
View Code Duplication |
public function setBody($body) |
|
|
|
|
218
|
|
|
{ |
219
|
14 |
|
if (is_array($body)) { |
220
|
13 |
|
$this->body = new BodyOptions($body); |
221
|
14 |
|
} elseif ($body instanceof BodyOptions) { |
222
|
1 |
|
$this->body = $body; |
223
|
1 |
|
} else { |
224
|
1 |
|
throw new InvalidArgumentException(sprintf( |
225
|
1 |
|
'Body should be an array or an AcMailer\\Options\\BodyOptions, %s provided', |
226
|
1 |
|
is_object($body) ? get_class($body) : gettype($body) |
227
|
1 |
|
)); |
228
|
|
|
} |
229
|
|
|
|
230
|
13 |
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return AttachmentsOptions |
235
|
|
|
*/ |
236
|
13 |
|
public function getAttachments() |
237
|
|
|
{ |
238
|
13 |
|
if (! isset($this->attachments)) { |
239
|
11 |
|
$this->setAttachments([]); |
240
|
11 |
|
} |
241
|
|
|
|
242
|
13 |
|
return $this->attachments; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param AttachmentsOptions|array $attachments |
247
|
|
|
* @return $this |
248
|
|
|
*/ |
249
|
14 |
View Code Duplication |
public function setAttachments($attachments) |
|
|
|
|
250
|
|
|
{ |
251
|
14 |
|
if (is_array($attachments)) { |
252
|
13 |
|
$this->attachments = new AttachmentsOptions($attachments); |
253
|
14 |
|
} elseif ($attachments instanceof AttachmentsOptions) { |
254
|
1 |
|
$this->attachments = $attachments; |
255
|
1 |
|
} else { |
256
|
1 |
|
throw new InvalidArgumentException(sprintf( |
257
|
1 |
|
'Attachments should be an array or an AcMailer\\Options\\AttachmentsOptions, %s provided', |
258
|
1 |
|
is_object($attachments) ? get_class($attachments) : gettype($attachments) |
259
|
1 |
|
)); |
260
|
|
|
} |
261
|
|
|
|
262
|
13 |
|
return $this; |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.