1
|
|
|
<?php |
2
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order\Box; |
3
|
|
|
|
4
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\National\UnregisteredParcelLockerMember; |
5
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging; |
6
|
|
|
use Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress; |
7
|
|
|
use Bpost\BpostApiClient\Bpost\ProductConfiguration\Product; |
8
|
|
|
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; |
9
|
|
|
use Bpost\BpostApiClient\Exception\BpostNotImplementedException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* bPost At247 class |
13
|
|
|
* |
14
|
|
|
* @author Tijs Verkoyen <[email protected]> |
15
|
|
|
* @version 3.0.0 |
16
|
|
|
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved. |
17
|
|
|
* @license BSD License |
18
|
|
|
*/ |
19
|
|
|
class At247 extends National |
20
|
|
|
{ |
21
|
|
|
/**@var string */ |
22
|
|
|
private $parcelsDepotId; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $parcelsDepotName; |
26
|
|
|
|
27
|
|
|
/** @var \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress */ |
28
|
|
|
private $parcelsDepotAddress; |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
protected $product = Product::PRODUCT_NAME_BPACK_24H_PRO; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
private $memberId; |
35
|
|
|
|
36
|
|
|
/** @var UnregisteredParcelLockerMember */ |
37
|
|
|
private $unregisteredParcelLockerMember; |
38
|
|
|
|
39
|
|
|
/** @var string */ |
40
|
|
|
private $receiverName; |
41
|
|
|
|
42
|
|
|
/** @var string */ |
43
|
|
|
private $receiverCompany; |
44
|
|
|
|
45
|
|
|
/** @var string */ |
46
|
|
|
protected $requestedDeliveryDate; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $memberId |
50
|
|
|
*/ |
51
|
1 |
|
public function setMemberId($memberId) |
52
|
|
|
{ |
53
|
1 |
|
$this->memberId = $memberId; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
1 |
|
public function getMemberId() |
60
|
|
|
{ |
61
|
1 |
|
return $this->memberId; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress $parcelsDepotAddress |
66
|
|
|
*/ |
67
|
1 |
|
public function setParcelsDepotAddress($parcelsDepotAddress) |
68
|
|
|
{ |
69
|
1 |
|
$this->parcelsDepotAddress = $parcelsDepotAddress; |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress |
74
|
|
|
*/ |
75
|
1 |
|
public function getParcelsDepotAddress() |
76
|
|
|
{ |
77
|
1 |
|
return $this->parcelsDepotAddress; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $parcelsDepotId |
82
|
|
|
*/ |
83
|
1 |
|
public function setParcelsDepotId($parcelsDepotId) |
84
|
|
|
{ |
85
|
1 |
|
$this->parcelsDepotId = $parcelsDepotId; |
86
|
1 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
1 |
|
public function getParcelsDepotId() |
92
|
|
|
{ |
93
|
1 |
|
return $this->parcelsDepotId; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $parcelsDepotName |
98
|
|
|
*/ |
99
|
1 |
|
public function setParcelsDepotName($parcelsDepotName) |
100
|
|
|
{ |
101
|
1 |
|
$this->parcelsDepotName = $parcelsDepotName; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
1 |
|
public function getParcelsDepotName() |
108
|
|
|
{ |
109
|
1 |
|
return $this->parcelsDepotName; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return UnregisteredParcelLockerMember |
114
|
|
|
*/ |
115
|
1 |
|
public function getUnregisteredParcelLockerMember() |
116
|
|
|
{ |
117
|
1 |
|
return $this->unregisteredParcelLockerMember; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param UnregisteredParcelLockerMember $unregisteredParcelLockerMember |
122
|
|
|
*/ |
123
|
1 |
|
public function setUnregisteredParcelLockerMember(UnregisteredParcelLockerMember $unregisteredParcelLockerMember) |
124
|
|
|
{ |
125
|
1 |
|
$this->unregisteredParcelLockerMember = $unregisteredParcelLockerMember; |
126
|
1 |
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param string $product Possible values are: bpack 24h Pro |
130
|
|
|
* |
131
|
|
|
* @throws BpostInvalidValueException |
132
|
2 |
|
*/ |
133
|
|
|
public function setProduct($product) |
134
|
2 |
|
{ |
135
|
1 |
|
if ( ! in_array($product, self::getPossibleProductValues())) { |
136
|
|
|
throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues()); |
137
|
|
|
} |
138
|
1 |
|
|
139
|
1 |
|
parent::setProduct($product); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return array |
144
|
2 |
|
*/ |
145
|
|
|
public static function getPossibleProductValues() |
146
|
|
|
{ |
147
|
2 |
|
return array( |
148
|
2 |
|
Product::PRODUCT_NAME_BPACK_24H_PRO, |
149
|
|
|
Product::PRODUCT_NAME_BPACK_24_7, |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
1 |
|
* @param string $receiverCompany |
155
|
|
|
*/ |
156
|
1 |
|
public function setReceiverCompany($receiverCompany) |
157
|
1 |
|
{ |
158
|
|
|
$this->receiverCompany = $receiverCompany; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
1 |
|
* @return string |
163
|
|
|
*/ |
164
|
1 |
|
public function getReceiverCompany() |
165
|
|
|
{ |
166
|
|
|
return $this->receiverCompany; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
1 |
|
* @param string $receiverName |
171
|
|
|
*/ |
172
|
1 |
|
public function setReceiverName($receiverName) |
173
|
1 |
|
{ |
174
|
|
|
$this->receiverName = $receiverName; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
1 |
|
* @return string |
179
|
|
|
*/ |
180
|
1 |
|
public function getReceiverName() |
181
|
|
|
{ |
182
|
|
|
return $this->receiverName; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
1 |
|
* @return string |
187
|
|
|
*/ |
188
|
1 |
|
public function getRequestedDeliveryDate() |
189
|
|
|
{ |
190
|
|
|
return $this->requestedDeliveryDate; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
1 |
|
* @param string $requestedDeliveryDate |
195
|
|
|
*/ |
196
|
1 |
|
public function setRequestedDeliveryDate($requestedDeliveryDate) |
197
|
1 |
|
{ |
198
|
|
|
$this->requestedDeliveryDate = (string)$requestedDeliveryDate; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Return the object as an array for usage in the XML |
203
|
|
|
* |
204
|
|
|
* @param \DomDocument $document |
205
|
|
|
* @param string $prefix |
|
|
|
|
206
|
|
|
* @param string $type |
|
|
|
|
207
|
1 |
|
* |
208
|
|
|
* @return \DomElement |
209
|
1 |
|
*/ |
210
|
1 |
|
public function toXML(\DOMDocument $document, $prefix = null, $type = null) |
211
|
|
|
{ |
212
|
|
|
$tagName = 'nationalBox'; |
213
|
1 |
|
if ($prefix !== null) { |
214
|
1 |
|
$tagName = $prefix . ':' . $tagName; |
215
|
1 |
|
} |
216
|
|
|
$nationalElement = $document->createElement($tagName); |
217
|
1 |
|
$boxElement = parent::toXML($document, null, 'at24-7'); |
218
|
1 |
|
$nationalElement->appendChild($boxElement); |
219
|
1 |
|
|
220
|
1 |
|
if ($this->getParcelsDepotId() !== null) { |
221
|
1 |
|
$boxElement->appendChild( |
222
|
1 |
|
$document->createElement('parcelsDepotId', $this->getParcelsDepotId()) |
223
|
1 |
|
); |
224
|
1 |
|
} |
225
|
1 |
|
if ($this->getParcelsDepotName() !== null) { |
226
|
1 |
|
$boxElement->appendChild( |
227
|
1 |
|
$document->createElement( |
228
|
1 |
|
'parcelsDepotName', |
229
|
1 |
|
$this->getParcelsDepotName() |
230
|
1 |
|
) |
231
|
1 |
|
); |
232
|
1 |
|
} |
233
|
1 |
|
if ($this->getParcelsDepotAddress() !== null) { |
234
|
1 |
|
$boxElement->appendChild( |
235
|
1 |
|
$this->getParcelsDepotAddress()->toXML($document) |
236
|
1 |
|
); |
237
|
1 |
|
} |
238
|
1 |
|
if ($this->getMemberId() !== null) { |
239
|
1 |
|
$boxElement->appendChild( |
240
|
1 |
|
$document->createElement( |
241
|
1 |
|
'memberId', |
242
|
1 |
|
$this->getMemberId() |
243
|
1 |
|
) |
244
|
1 |
|
); |
245
|
1 |
|
} |
246
|
1 |
|
$this->addToXmlUnregisteredParcelLockerMember($document, $boxElement, $prefix); |
247
|
1 |
|
if ($this->getReceiverName() !== null) { |
248
|
1 |
|
$boxElement->appendChild( |
249
|
1 |
|
$document->createElement( |
250
|
1 |
|
'receiverName', |
251
|
1 |
|
$this->getReceiverName() |
252
|
1 |
|
) |
253
|
1 |
|
); |
254
|
1 |
|
} |
255
|
1 |
|
if ($this->getReceiverCompany() !== null) { |
256
|
1 |
|
$boxElement->appendChild( |
257
|
1 |
|
$document->createElement( |
258
|
1 |
|
'receiverCompany', |
259
|
1 |
|
$this->getReceiverCompany() |
260
|
1 |
|
) |
261
|
|
|
); |
262
|
1 |
|
} |
263
|
|
|
$this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); |
264
|
|
|
|
265
|
|
|
return $nationalElement; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @param \DOMDocument $document |
270
|
1 |
|
* @param \DOMElement $typeElement |
271
|
|
|
* @param string $prefix |
272
|
1 |
|
*/ |
273
|
1 |
|
protected function addToXmlRequestedDeliveryDate(\DOMDocument $document, \DOMElement $typeElement, $prefix) |
274
|
1 |
|
{ |
275
|
1 |
|
if ($this->getRequestedDeliveryDate() !== null) { |
276
|
1 |
|
$typeElement->appendChild( |
277
|
1 |
|
$document->createElement( |
278
|
1 |
|
$this->getPrefixedTagName('requestedDeliveryDate', $prefix), |
279
|
1 |
|
$this->getRequestedDeliveryDate() |
280
|
1 |
|
) |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @param \DOMDocument $document |
287
|
1 |
|
* @param \DOMElement $typeElement |
288
|
|
|
* @param string $prefix |
289
|
1 |
|
*/ |
290
|
1 |
|
protected function addToXmlUnregisteredParcelLockerMember(\DOMDocument $document, \DOMElement $typeElement, $prefix) |
|
|
|
|
291
|
1 |
|
{ |
292
|
1 |
|
if ($this->getUnregisteredParcelLockerMember() !== null) { |
293
|
1 |
|
$typeElement->appendChild( |
294
|
1 |
|
$this->getUnregisteredParcelLockerMember()->toXml($document) |
295
|
|
|
); |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param \SimpleXMLElement $xml |
301
|
|
|
* |
302
|
|
|
* @return At247 |
303
|
|
|
* @throws BpostInvalidValueException |
304
|
|
|
* @throws BpostNotImplementedException |
305
|
|
|
*/ |
306
|
|
|
public static function createFromXML(\SimpleXMLElement $xml) |
307
|
|
|
{ |
308
|
|
|
$at247 = new At247(); |
309
|
|
|
|
310
|
|
|
if (isset($xml->{'at24-7'}->product) && $xml->{'at24-7'}->product != '') { |
311
|
|
|
$at247->setProduct( |
312
|
|
|
(string)$xml->{'at24-7'}->product |
313
|
|
|
); |
314
|
|
|
} |
315
|
|
View Code Duplication |
if (isset($xml->{'at24-7'}->options)) { |
|
|
|
|
316
|
|
|
/** @var \SimpleXMLElement $optionData */ |
317
|
|
|
foreach ($xml->{'at24-7'}->options as $optionData) { |
318
|
|
|
$optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); |
319
|
|
|
|
320
|
|
|
if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED))) { |
321
|
|
|
$option = Messaging::createFromXML($optionData); |
322
|
|
|
} else { |
323
|
|
|
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName()); |
324
|
|
|
if ( ! method_exists($className, 'createFromXML')) { |
325
|
|
|
throw new BpostNotImplementedException(); |
326
|
|
|
} |
327
|
|
|
$option = call_user_func( |
328
|
|
|
array($className, 'createFromXML'), |
329
|
|
|
$optionData |
330
|
|
|
); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
$at247->addOption($option); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
if (isset($xml->{'at24-7'}->weight) && $xml->{'at24-7'}->weight != '') { |
337
|
|
|
$at247->setWeight( |
338
|
|
|
(int)$xml->{'at24-7'}->weight |
339
|
|
|
); |
340
|
|
|
} |
341
|
|
|
if (isset($xml->{'at24-7'}->memberId) && $xml->{'at24-7'}->memberId != '') { |
342
|
|
|
$at247->setMemberId( |
343
|
|
|
(string)$xml->{'at24-7'}->memberId |
344
|
|
|
); |
345
|
|
|
} |
346
|
|
|
if (isset($xml->{'at24-7'}->receiverName) && $xml->{'at24-7'}->receiverName != '') { |
347
|
|
|
$at247->setReceiverName( |
348
|
|
|
(string)$xml->{'at24-7'}->receiverName |
349
|
|
|
); |
350
|
|
|
} |
351
|
|
|
if (isset($xml->{'at24-7'}->receiverCompany) && $xml->{'at24-7'}->receiverCompany != '') { |
352
|
|
|
$at247->setReceiverCompany( |
353
|
|
|
(string)$xml->{'at24-7'}->receiverCompany |
354
|
|
|
); |
355
|
|
|
} |
356
|
|
|
if (isset($xml->{'at24-7'}->parcelsDepotId) && $xml->{'at24-7'}->parcelsDepotId != '') { |
357
|
|
|
$at247->setParcelsDepotId( |
358
|
|
|
(string)$xml->{'at24-7'}->parcelsDepotId |
359
|
|
|
); |
360
|
|
|
} |
361
|
|
|
if (isset($xml->{'at24-7'}->parcelsDepotName) && $xml->{'at24-7'}->parcelsDepotName != '') { |
362
|
|
|
$at247->setParcelsDepotName( |
363
|
|
|
(string)$xml->{'at24-7'}->parcelsDepotName |
364
|
|
|
); |
365
|
|
|
} |
366
|
|
|
if (isset($xml->{'at24-7'}->parcelsDepotAddress)) { |
367
|
|
|
/** @var \SimpleXMLElement $parcelsDepotAddressData */ |
368
|
|
|
$parcelsDepotAddressData = $xml->{'at24-7'}->parcelsDepotAddress->children( |
369
|
|
|
'http://schema.post.be/shm/deepintegration/v3/common' |
370
|
|
|
); |
371
|
|
|
$at247->setParcelsDepotAddress( |
372
|
|
|
ParcelsDepotAddress::createFromXML($parcelsDepotAddressData) |
373
|
|
|
); |
374
|
|
|
} |
375
|
|
|
if (isset($xml->{'at24-7'}->requestedDeliveryDate) && $xml->{'at24-7'}->requestedDeliveryDate != '') { |
376
|
|
|
$at247->setRequestedDeliveryDate( |
377
|
|
|
(string)$xml->{'at24-7'}->requestedDeliveryDate |
378
|
|
|
); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
return $at247; |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.