|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order\Box; |
|
5
|
|
|
|
|
6
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Receiver; |
|
7
|
|
|
use Bpost\BpostApiClient\Common\XmlHelper; |
|
8
|
|
|
use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException; |
|
9
|
|
|
use DOMDocument; |
|
10
|
|
|
use DOMElement; |
|
11
|
|
|
use SimpleXMLElement; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class BpostOnAppointment |
|
15
|
|
|
*/ |
|
16
|
|
|
class BpostOnAppointment extends National |
|
17
|
|
|
{ |
|
18
|
|
|
private ?Receiver $receiver = null; |
|
19
|
|
|
protected ?string $inNetworkCutOff = null; |
|
20
|
|
|
|
|
21
|
|
|
public function setReceiver(?Receiver $receiver): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->receiver = $receiver; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getReceiver(): ?Receiver |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->receiver; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getInNetworkCutOff(): ?string |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->inNetworkCutOff; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setInNetworkCutOff(?string $inNetworkCutOff): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->inNetworkCutOff = $inNetworkCutOff; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function toXML(DOMDocument $document, ?string $prefix = null, ?string $type = null): DOMElement |
|
42
|
|
|
{ |
|
43
|
|
|
$nationalElement = $document->createElement(XmlHelper::getPrefixedTagName('nationalBox', $prefix)); |
|
44
|
|
|
$boxElement = parent::toXML($document, null, 'bpostOnAppointment'); |
|
45
|
|
|
$nationalElement->appendChild($boxElement); |
|
46
|
|
|
|
|
47
|
|
|
$this->addToXmlReceiver($document, $boxElement); |
|
48
|
|
|
$this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); |
|
49
|
|
|
|
|
50
|
|
|
return $nationalElement; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function addToXmlReceiver(DOMDocument $document, DOMElement $typeElement): void |
|
54
|
|
|
{ |
|
55
|
|
|
if ($this->receiver !== null) { |
|
56
|
|
|
$typeElement->appendChild($this->receiver->toXML($document)); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @throws \DOMException |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function addToXmlRequestedDeliveryDate(DOMDocument $document, DOMElement $typeElement, ?string $prefix): void |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->inNetworkCutOff !== null && $this->inNetworkCutOff !== '') { |
|
66
|
|
|
$typeElement->appendChild( |
|
67
|
|
|
$document->createElement( |
|
68
|
|
|
XmlHelper::getPrefixedTagName('inNetworkCutOff', $prefix), |
|
69
|
|
|
$this->inNetworkCutOff |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public static function createFromXML(SimpleXMLElement $xml, National $self = null): BpostOnAppointment |
|
76
|
|
|
{ |
|
77
|
|
|
$self = new self(); |
|
78
|
|
|
|
|
79
|
|
|
if (!isset($xml->bpostOnAppointment)) { |
|
80
|
|
|
throw new BpostXmlInvalidItemException(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$bpostOnAppointmentXml = $xml->bpostOnAppointment; |
|
84
|
|
|
|
|
85
|
|
|
if (isset($bpostOnAppointmentXml->receiver)) { |
|
86
|
|
|
$self->setReceiver( |
|
87
|
|
|
Receiver::createFromXML( |
|
88
|
|
|
$bpostOnAppointmentXml->receiver->children('http://schema.post.be/shm/deepintegration/v3/common') |
|
89
|
|
|
) |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (isset($bpostOnAppointmentXml->inNetworkCutOff) && (string)$bpostOnAppointmentXml->inNetworkCutOff !== '') { |
|
94
|
|
|
$self->setInNetworkCutOff((string)$bpostOnAppointmentXml->inNetworkCutOff); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $self; |
|
98
|
|
|
} |
|
99
|
|
|
} |