1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
class EmailMessage implements NodeInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $emailAddresses = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $undeliverableEmailAddress; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $fromEmailAddress; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $fromName; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $memo; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $subject; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $subjectCode; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Subject codes. |
48
|
|
|
*/ |
49
|
|
|
const SUBJECT_CODE_SHIPMENT_REFERENCE_NR1 = '01'; |
50
|
|
|
const SUBJECT_CODE_SHIPMENT_REFERENCE_NR2 = '02'; |
51
|
|
|
const SUBJECT_CODE_SHIPMENT_PACKAGE_NR1 = '03'; |
52
|
|
|
const SUBJECT_CODE_SHIPMENT_PACKAGE_NR2 = '04'; |
53
|
|
|
const SUBJECT_CODE_SUBJECT_TEXT = '08'; // Return only |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param null|DOMDocument $document |
57
|
|
|
* |
58
|
|
|
* @return DOMElement |
59
|
|
|
*/ |
60
|
|
|
public function toNode(DOMDocument $document = null) |
61
|
|
|
{ |
62
|
|
|
if (null === $document) { |
63
|
|
|
$document = new DOMDocument(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$node = $document->createElement('EMailMessage'); |
67
|
|
|
|
68
|
|
|
foreach ($this->getEmailAddresses() as $email) { |
69
|
|
|
$node->appendChild($document->createElement('EMailAddress', $email)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ($this->getUndeliverableEmailAddress() !== null) { |
73
|
|
|
$node->appendChild($document->createElement('UndeliverableEMailAddress', $this->getUndeliverableEmailAddress())); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if ($this->getFromEmailAddress() !== null) { |
77
|
|
|
$node->appendChild($document->createElement('FromEMailAddress', $this->getFromEmailAddress())); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($this->getFromName() !== null) { |
81
|
|
|
$node->appendChild($document->createElement('FromName', $this->getFromName())); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($this->getMemo() !== null) { |
85
|
|
|
$node->appendChild($document->createElement('Memo', $this->getMemo())); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($this->getSubject() !== null) { |
89
|
|
|
$node->appendChild($document->createElement('Subject', $this->getSubject())); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($this->getSubjectCode() !== null) { |
93
|
|
|
$node->appendChild($document->createElement('SubjectCode', $this->getSubjectCode())); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $node; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
public function getEmailAddresses() |
103
|
|
|
{ |
104
|
|
|
return $this->emailAddresses; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param array $emailAddresses |
109
|
|
|
* |
110
|
|
|
* @throws \Exception |
111
|
|
|
*/ |
112
|
|
|
public function setEmailAddresses(array $emailAddresses) |
113
|
|
|
{ |
114
|
|
|
if (count($emailAddresses) > 5) { |
115
|
|
|
throw new \Exception('Maximum of 5 emailaddresses allowed'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->emailAddresses = $emailAddresses; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return mixed |
123
|
|
|
*/ |
124
|
|
|
public function getUndeliverableEmailAddress() |
125
|
|
|
{ |
126
|
|
|
return $this->undeliverableEmailAddress; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param mixed $undeliverableEmailAddress |
131
|
|
|
*/ |
132
|
|
|
public function setUndeliverableEmailAddress($undeliverableEmailAddress) |
133
|
|
|
{ |
134
|
|
|
$this->undeliverableEmailAddress = $undeliverableEmailAddress; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return mixed |
139
|
|
|
*/ |
140
|
|
|
public function getFromEmailAddress() |
141
|
|
|
{ |
142
|
|
|
return $this->fromEmailAddress; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param mixed $fromEmailAddress |
147
|
|
|
*/ |
148
|
|
|
public function setFromEmailAddress($fromEmailAddress) |
149
|
|
|
{ |
150
|
|
|
$this->fromEmailAddress = $fromEmailAddress; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return mixed |
155
|
|
|
*/ |
156
|
|
|
public function getFromName() |
157
|
|
|
{ |
158
|
|
|
return $this->fromName; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param mixed $fromName |
163
|
|
|
*/ |
164
|
|
|
public function setFromName($fromName) |
165
|
|
|
{ |
166
|
|
|
$this->fromName = $fromName; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return mixed |
171
|
|
|
*/ |
172
|
|
|
public function getMemo() |
173
|
|
|
{ |
174
|
|
|
return $this->memo; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param mixed $memo |
179
|
|
|
* |
180
|
|
|
* @throws \Exception |
181
|
|
|
*/ |
182
|
|
|
public function setMemo($memo) |
183
|
|
|
{ |
184
|
|
|
if (strlen($memo) > 50) { |
185
|
|
|
throw new \Exception('Memo should maximum be 50 chars'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$this->memo = $memo; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return mixed |
193
|
|
|
*/ |
194
|
|
|
public function getSubject() |
195
|
|
|
{ |
196
|
|
|
return $this->subject; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param mixed $subject |
201
|
|
|
* |
202
|
|
|
* @throws \Exception |
203
|
|
|
*/ |
204
|
|
|
public function setSubject($subject) |
205
|
|
|
{ |
206
|
|
|
if (strlen($subject) > 50) { |
207
|
|
|
throw new \Exception('Subject should maximum be 50 chars'); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$this->subject = $subject; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return mixed |
215
|
|
|
*/ |
216
|
|
|
public function getSubjectCode() |
217
|
|
|
{ |
218
|
|
|
return $this->subjectCode; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param mixed $subjectCode |
223
|
|
|
*/ |
224
|
|
|
public function setSubjectCode($subjectCode) |
225
|
|
|
{ |
226
|
|
|
$this->subjectCode = $subjectCode; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|