-
Notifications
You must be signed in to change notification settings - Fork 44
/
AtHome.php
162 lines (140 loc) · 4.45 KB
/
AtHome.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace Bpost\BpostApiClient\Bpost\Order\Box;
use Bpost\BpostApiClient\Bpost\Order\Receiver;
use Bpost\BpostApiClient\Bpost\ProductConfiguration\Product;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
use Bpost\BpostApiClient\Exception\BpostNotImplementedException;
use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException;
/**
* bPost AtHome class
*
* @author Tijs Verkoyen <php-bpost@verkoyen.eu>
* @version 3.0.0
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved.
* @license BSD License
*/
class AtHome extends National
{
/** @var \Bpost\BpostApiClient\Bpost\Order\Receiver */
private $receiver;
/** @var string */
protected $requestedDeliveryDate;
/**
* @param string $product
* @see getPossibleProductValues
* @throws BpostInvalidValueException
*/
public function setProduct($product)
{
if (!in_array($product, self::getPossibleProductValues())) {
throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues());
}
parent::setProduct($product);
}
/**
* @return array
*/
public static function getPossibleProductValues()
{
return array(
Product::PRODUCT_NAME_BPACK_24H_PRO,
Product::PRODUCT_NAME_BPACK_24H_BUSINESS,
Product::PRODUCT_NAME_BPACK_BUSINESS,
Product::PRODUCT_NAME_BPACK_PALLET,
Product::PRODUCT_NAME_BPACK_EASY_RETOUR,
);
}
/**
* @param \Bpost\BpostApiClient\Bpost\Order\Receiver $receiver
*/
public function setReceiver($receiver)
{
$this->receiver = $receiver;
}
/**
* @return \Bpost\BpostApiClient\Bpost\Order\Receiver
*/
public function getReceiver()
{
return $this->receiver;
}
/**
* @return string
*/
public function getRequestedDeliveryDate()
{
return $this->requestedDeliveryDate;
}
/**
* @param string $requestedDeliveryDate
*/
public function setRequestedDeliveryDate($requestedDeliveryDate)
{
$this->requestedDeliveryDate = (string)$requestedDeliveryDate;
}
/**
* Return the object as an array for usage in the XML
*
* @param \DomDocument $document
* @param string $prefix
* @param string $type
* @return \DomElement
*/
public function toXML(\DOMDocument $document, $prefix = null, $type = null)
{
$nationalElement = $document->createElement($this->getPrefixedTagName('nationalBox', $prefix));
$boxElement = parent::toXML($document, null, 'atHome');
$nationalElement->appendChild($boxElement);
if ($this->getReceiver() !== null) {
$boxElement->appendChild(
$this->getReceiver()->toXML($document)
);
}
$this->addToXmlRequestedDeliveryDate($document, $boxElement);
return $nationalElement;
}
/**
* @param \DOMDocument $document
* @param \DOMElement $typeElement
*/
protected function addToXmlRequestedDeliveryDate(\DOMDocument $document, \DOMElement $typeElement)
{
if ($this->getRequestedDeliveryDate() !== null) {
$typeElement->appendChild(
$document->createElement(
'requestedDeliveryDate',
$this->getRequestedDeliveryDate()
)
);
}
}
/**
* @param \SimpleXMLElement $xml
* @return AtHome
* @throws BpostNotImplementedException
* @throws BpostXmlInvalidItemException
* @throws \Bpost\BpostApiClient\BpostException
*/
public static function createFromXML(\SimpleXMLElement $xml)
{
$self = new self();
if (!isset($xml->atHome)) {
throw new BpostXmlInvalidItemException();
}
$atHomeXml = $xml->atHome[0];
$self = parent::createFromXML($atHomeXml, $self);
if (isset($atHomeXml->receiver)) {
$self->setReceiver(
Receiver::createFromXML(
$atHomeXml->receiver->children('http://schema.post.be/shm/deepintegration/v3/common')
)
);
}
if (isset($atHomeXml->requestedDeliveryDate) && $atHomeXml->requestedDeliveryDate != '') {
$self->setRequestedDeliveryDate(
$atHomeXml->requestedDeliveryDate
);
}
return $self;
}
}