1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity\Tradeability; |
4
|
|
|
|
5
|
|
|
use DomDocument; |
6
|
|
|
use DomElement; |
7
|
|
|
use Ups\Entity\FreightCharges; |
|
|
|
|
8
|
|
|
use Ups\NodeInterface; |
9
|
|
|
|
10
|
|
|
class Shipment implements NodeInterface |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
const TRANSPORT_MODE_AIR = 1; |
14
|
|
|
const TRANSPORT_MODE_GROUND = 2; |
15
|
|
|
const TRANSPORT_MODE_RAIL = 3; |
16
|
|
|
const TRANSPORT_MODE_OCEAN = 4; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $originCountryCode; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $originStateProvinceCode; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $destinationCountryCode; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $destinationStateProvinceCode; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
private $transportationMode; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var FreightCharges |
45
|
|
|
*/ |
46
|
|
|
private $freightCharges; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var mixed |
50
|
|
|
*/ |
51
|
|
|
private $additionalInsurance; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
private $products = []; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private $resultCurrencyCode; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var |
65
|
|
|
*/ |
66
|
|
|
private $transactionReferenceId; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var int |
70
|
|
|
*/ |
71
|
|
|
private $tariffCodeAlert; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param null|DOMDocument $document |
75
|
|
|
* |
76
|
|
|
* @return DOMElement |
77
|
|
|
*/ |
78
|
1 |
|
public function toNode(DOMDocument $document = null) |
79
|
|
|
{ |
80
|
1 |
|
if (null === $document) { |
81
|
|
|
$document = new DOMDocument(); |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
$node = $document->createElement('Shipment'); |
85
|
|
|
|
86
|
1 |
|
if ($this->getFreightCharges() instanceof FreightCharges) { |
87
|
1 |
|
$node->appendChild($this->getFreightCharges()->toNode($document)); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
// Then the required values |
91
|
1 |
|
$node->appendChild($document->createElement('OriginCountryCode', $this->getOriginCountryCode())); |
92
|
1 |
|
$node->appendChild($document->createElement('DestinationCountryCode', $this->getDestinationCountryCode())); |
93
|
|
|
|
94
|
|
|
// Then the optional values |
95
|
1 |
|
if ($this->getOriginStateProvinceCode() !== null) { |
96
|
|
|
$node->appendChild( |
97
|
|
|
$document->createElement( |
98
|
|
|
'OriginStateProvinceCode', |
99
|
|
|
$this->getOriginStateProvinceCode() |
100
|
|
|
) |
101
|
|
|
); |
102
|
|
|
} |
103
|
1 |
|
if ($this->getDestinationStateProvinceCode() !== null) { |
104
|
1 |
|
$node->appendChild( |
105
|
1 |
|
$document->createElement( |
106
|
1 |
|
'DestinationStateProvinceCode', |
107
|
1 |
|
$this->getDestinationStateProvinceCode() |
108
|
1 |
|
) |
109
|
1 |
|
); |
110
|
1 |
|
} |
111
|
1 |
|
if ($this->getTransportationMode() !== null) { |
112
|
1 |
|
$node->appendChild($document->createElement('TransportationMode', $this->getTransportationMode())); |
113
|
1 |
|
} |
114
|
1 |
|
if ($this->getResultCurrencyCode() !== null) { |
115
|
1 |
|
$node->appendChild($document->createElement('ResultCurrencyCode', $this->getResultCurrencyCode())); |
116
|
1 |
|
} |
117
|
1 |
|
if ($this->getTariffCodeAlert() !== null) { |
118
|
1 |
|
$node->appendChild($document->createElement('TariffCodeAlert', $this->getTariffCodeAlert())); |
119
|
1 |
|
} |
120
|
1 |
|
if ($this->getTransactionReferenceId() !== null) { |
121
|
|
|
$node->appendChild($document->createElement('TransactionReferenceID', $this->getTransactionReferenceId())); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// Then products array |
125
|
1 |
|
foreach ($this->products as $product) { |
126
|
1 |
|
$node->appendChild($product->toNode($document)); |
127
|
1 |
|
} |
128
|
|
|
|
129
|
|
|
// Return created node |
130
|
1 |
|
return $node; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return mixed |
135
|
|
|
*/ |
136
|
|
|
public function getAdditionalInsurance() |
137
|
|
|
{ |
138
|
|
|
return $this->additionalInsurance; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param mixed $additionalInsurance |
143
|
|
|
* |
144
|
|
|
* @return $this |
145
|
|
|
*/ |
146
|
|
|
public function setAdditionalInsurance($additionalInsurance) |
147
|
|
|
{ |
148
|
|
|
$this->additionalInsurance = $additionalInsurance; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return FreightCharges |
155
|
|
|
*/ |
156
|
1 |
|
public function getFreightCharges() |
157
|
|
|
{ |
158
|
1 |
|
return $this->freightCharges; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param FreightCharges $freightCharges |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
1 |
|
public function setFreightCharges($freightCharges) |
166
|
|
|
{ |
167
|
1 |
|
$this->freightCharges = $freightCharges; |
168
|
|
|
|
169
|
1 |
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
1 |
|
public function getOriginCountryCode() |
176
|
|
|
{ |
177
|
1 |
|
return $this->originCountryCode; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $originCountryCode |
182
|
|
|
* @return $this |
183
|
|
|
*/ |
184
|
1 |
|
public function setOriginCountryCode($originCountryCode) |
185
|
|
|
{ |
186
|
1 |
|
$this->originCountryCode = $originCountryCode; |
187
|
|
|
|
188
|
1 |
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
1 |
|
public function getDestinationCountryCode() |
195
|
|
|
{ |
196
|
1 |
|
return $this->destinationCountryCode; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $destinationCountryCode |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
1 |
|
public function setDestinationCountryCode($destinationCountryCode) |
204
|
|
|
{ |
205
|
1 |
|
$this->destinationCountryCode = $destinationCountryCode; |
206
|
|
|
|
207
|
1 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
1 |
|
public function getOriginStateProvinceCode() |
214
|
|
|
{ |
215
|
1 |
|
return $this->originStateProvinceCode; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param string $originStateProvinceCode |
220
|
|
|
* @return $this |
221
|
|
|
*/ |
222
|
|
|
public function setOriginStateProvinceCode($originStateProvinceCode) |
223
|
|
|
{ |
224
|
|
|
$this->originStateProvinceCode = $originStateProvinceCode; |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return string |
231
|
|
|
*/ |
232
|
1 |
|
public function getDestinationStateProvinceCode() |
233
|
|
|
{ |
234
|
1 |
|
return $this->destinationStateProvinceCode; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param string $destinationStateProvinceCode |
239
|
|
|
* @return $this |
240
|
|
|
*/ |
241
|
1 |
|
public function setDestinationStateProvinceCode($destinationStateProvinceCode) |
242
|
|
|
{ |
243
|
1 |
|
$this->destinationStateProvinceCode = $destinationStateProvinceCode; |
244
|
|
|
|
245
|
1 |
|
return $this; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return int |
250
|
|
|
*/ |
251
|
1 |
|
public function getTransportationMode() |
252
|
|
|
{ |
253
|
1 |
|
return $this->transportationMode; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @param int $transportationMode |
258
|
|
|
* @return $this |
259
|
|
|
*/ |
260
|
1 |
|
public function setTransportationMode($transportationMode) |
261
|
|
|
{ |
262
|
1 |
|
$this->transportationMode = $transportationMode; |
263
|
|
|
|
264
|
1 |
|
return $this; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @return string |
269
|
|
|
*/ |
270
|
1 |
|
public function getResultCurrencyCode() |
271
|
|
|
{ |
272
|
1 |
|
return $this->resultCurrencyCode; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @param string $resultCurrencyCode |
277
|
|
|
* @return $this |
278
|
|
|
*/ |
279
|
1 |
|
public function setResultCurrencyCode($resultCurrencyCode) |
280
|
|
|
{ |
281
|
1 |
|
$this->resultCurrencyCode = $resultCurrencyCode; |
282
|
|
|
|
283
|
1 |
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @return int |
288
|
|
|
*/ |
289
|
1 |
|
public function getTariffCodeAlert() |
290
|
|
|
{ |
291
|
1 |
|
return $this->tariffCodeAlert; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param int $tariffCodeAlert |
296
|
|
|
* @return Shipment |
297
|
|
|
*/ |
298
|
1 |
|
public function setTariffCodeAlert($tariffCodeAlert) |
299
|
|
|
{ |
300
|
1 |
|
$this->tariffCodeAlert = $tariffCodeAlert; |
301
|
|
|
|
302
|
1 |
|
return $this; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return mixed |
307
|
|
|
*/ |
308
|
1 |
|
public function getTransactionReferenceId() |
309
|
|
|
{ |
310
|
1 |
|
return $this->transactionReferenceId; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @param mixed $transactionReferenceId |
315
|
|
|
* @return $this |
316
|
|
|
*/ |
317
|
|
|
public function setTransactionReferenceId($transactionReferenceId) |
318
|
|
|
{ |
319
|
|
|
$this->transactionReferenceId = $transactionReferenceId; |
320
|
|
|
|
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @return array |
326
|
|
|
*/ |
327
|
|
|
public function getProducts() |
328
|
|
|
{ |
329
|
|
|
return $this->products; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @param array $products |
334
|
|
|
* @return $this |
335
|
|
|
*/ |
336
|
|
|
public function setProducts($products) |
337
|
|
|
{ |
338
|
|
|
$this->products = $products; |
339
|
|
|
|
340
|
|
|
return $this; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @param Product $product |
345
|
|
|
* @return $this |
346
|
|
|
*/ |
347
|
1 |
|
public function addProduct(Product $product) |
348
|
|
|
{ |
349
|
1 |
|
array_push($this->products, $product); |
350
|
|
|
|
351
|
1 |
|
return $this; |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: