Skip to content

Commit ed4d511

Browse files
committed
refactor: xml namespaces are stoored ein php constants
1 parent f80989d commit ed4d511

29 files changed

+147
-389
lines changed

src/Bpost.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ class Bpost
4343
const LABEL_FORMAT_A4 = 'A4';
4444
const LABEL_FORMAT_A6 = 'A6';
4545

46+
const NS_V3_GLOBAL = 'http://schema.post.be/shm/deepintegration/v3/';
47+
const NS_V3_COMMON = 'http://schema.post.be/shm/deepintegration/v3/common';
48+
const NS_V3_NATIONAL = 'http://schema.post.be/shm/deepintegration/v3/national';
49+
const NS_V3_INTERNATIONAL = 'http://schema.post.be/shm/deepintegration/v3/international';
50+
const NS_V5_GLOBAL = 'http://schema.post.be/shm/deepintegration/v5/';
51+
const NS_V5_COMMON = 'http://schema.post.be/shm/deepintegration/v5/common';
52+
const NS_V5_NATIONAL = 'http://schema.post.be/shm/deepintegration/v5/national';
53+
const NS_V5_INTERNATIONAL = 'http://schema.post.be/shm/deepintegration/v5/international';
54+
4655
// URL for the api
4756
const API_URL = 'https://shm-rest.bpost.cloud/services/shm';
4857

src/Bpost/HttpRequestBuilder/CreateLabelInBulkForOrdersBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\HttpRequestBuilder;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Common\ValidatedValue\LabelFormat;
67
use DOMDocument;
78
use DOMException;
@@ -57,7 +58,7 @@ public function getXml()
5758
$document->formatOutput = true;
5859

5960
$batchLabels = $document->createElement('batchLabels');
60-
$batchLabels->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/');
61+
$batchLabels->setAttribute('xmlns', Bpost::NS_V3_GLOBAL);
6162
foreach ($this->references as $reference) {
6263
$batchLabels->appendChild(
6364
$document->createElement('order', $reference)

src/Bpost/HttpRequestBuilder/ModifyOrderBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\HttpRequestBuilder;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Bpost\Order\Box;
67
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
78
use DOMDocument;
@@ -40,7 +41,7 @@ public function getXml()
4041
$document->formatOutput = true;
4142

4243
$orderUpdate = $document->createElement('orderUpdate');
43-
$orderUpdate->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/');
44+
$orderUpdate->setAttribute('xmlns', Bpost::NS_V3_GLOBAL);
4445
$orderUpdate->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
4546
$orderUpdate->appendChild(
4647
$document->createElement('status', $this->status)

src/Bpost/Order.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Bpost\Order\Box;
67
use Bpost\BpostApiClient\Bpost\Order\Line;
78
use Bpost\BpostApiClient\Exception\BpostNotImplementedException;
@@ -158,30 +159,12 @@ public function toXML(DOMDocument $document, $accountId)
158159
$order = $document->createElement(
159160
'tns:order'
160161
);
161-
$order->setAttribute(
162-
'xmlns:common',
163-
'http://schema.post.be/shm/deepintegration/v5/common'
164-
);
165-
$order->setAttribute(
166-
'xmlns:tns',
167-
'http://schema.post.be/shm/deepintegration/v5/'
168-
);
169-
$order->setAttribute(
170-
'xmlns',
171-
'http://schema.post.be/shm/deepintegration/v5/national'
172-
);
173-
$order->setAttribute(
174-
'xmlns:international',
175-
'http://schema.post.be/shm/deepintegration/v5/international'
176-
);
177-
$order->setAttribute(
178-
'xmlns:xsi',
179-
'http://www.w3.org/2001/XMLSchema-instance'
180-
);
181-
$order->setAttribute(
182-
'xsi:schemaLocation',
183-
'http://schema.post.be/shm/deepintegration/v5/'
184-
);
162+
$order->setAttribute('xmlns:common', Bpost::NS_V5_COMMON);
163+
$order->setAttribute('xmlns:tns', Bpost::NS_V5_GLOBAL);
164+
$order->setAttribute('xmlns', Bpost::NS_V5_NATIONAL);
165+
$order->setAttribute('xmlns:international', Bpost::NS_V5_INTERNATIONAL);
166+
$order->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
167+
$order->setAttribute('xsi:schemaLocation', Bpost::NS_V5_GLOBAL);
185168

186169
$document->appendChild($order);
187170

src/Bpost/Order/Box.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\Order;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Common\XmlHelper;
67
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
78
use Bpost\BpostApiClient\Exception\BpostNotImplementedException;
@@ -232,14 +233,14 @@ public static function createFromXML(SimpleXMLElement $xml)
232233
$box->setSender(
233234
Sender::createFromXML(
234235
$xml->sender->children(
235-
'http://schema.post.be/shm/deepintegration/v3/common'
236+
Bpost::NS_V3_COMMON
236237
)
237238
)
238239
);
239240
}
240241
if (isset($xml->nationalBox)) {
241242
/** @var SimpleXMLElement $nationalBoxData */
242-
$nationalBoxData = $xml->nationalBox->children('http://schema.post.be/shm/deepintegration/v3/national');
243+
$nationalBoxData = $xml->nationalBox->children(Bpost::NS_V3_NATIONAL);
243244

244245
// build classname based on the tag name
245246
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($nationalBoxData->getName());
@@ -255,7 +256,7 @@ public static function createFromXML(SimpleXMLElement $xml)
255256
}
256257
if (isset($xml->internationalBox)) {
257258
/** @var SimpleXMLElement $internationalBoxData */
258-
$internationalBoxData = $xml->internationalBox->children('http://schema.post.be/shm/deepintegration/v3/international');
259+
$internationalBoxData = $xml->internationalBox->children(Bpost::NS_V3_INTERNATIONAL);
259260

260261
// build classname based on the tag name
261262
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($internationalBoxData->getName());

src/Bpost/Order/Box/At247.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\Order\Box;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Bpost\Order\Box\National\Unregistered;
67
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging;
78
use Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress;
@@ -322,7 +323,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul
322323
if (isset($xml->{'at24-7'}->options)) {
323324
/** @var SimpleXMLElement $optionData */
324325
foreach ($xml->{'at24-7'}->options as $optionData) {
325-
$optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
326+
$optionData = $optionData->children(Bpost::NS_V3_COMMON);
326327

327328
if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED))) {
328329
$option = Messaging::createFromXML($optionData);
@@ -365,9 +366,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul
365366
}
366367
if (isset($xml->{'at24-7'}->parcelsDepotAddress)) {
367368
/** @var SimpleXMLElement $parcelsDepotAddressData */
368-
$parcelsDepotAddressData = $xml->{'at24-7'}->parcelsDepotAddress->children(
369-
'http://schema.post.be/shm/deepintegration/v3/common'
370-
);
369+
$parcelsDepotAddressData = $xml->{'at24-7'}->parcelsDepotAddress->children(Bpost::NS_V3_COMMON);
371370
$at247->setParcelsDepotAddress(
372371
ParcelsDepotAddress::createFromXML($parcelsDepotAddressData)
373372
);

src/Bpost/Order/Box/AtBpost.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\Order\Box;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Bpost\Order\Box\National\ShopHandlingInstruction;
67
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging;
78
use Bpost\BpostApiClient\Bpost\Order\PugoAddress;
@@ -281,7 +282,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul
281282
if (isset($xml->atBpost->options)) {
282283
/** @var SimpleXMLElement $optionData */
283284
foreach ($xml->atBpost->options as $optionData) {
284-
$optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
285+
$optionData = $optionData->children(Bpost::NS_V3_COMMON);
285286

286287
if (in_array(
287288
$optionData->getName(),
@@ -329,7 +330,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul
329330
if (isset($xml->atBpost->pugoAddress)) {
330331
/** @var SimpleXMLElement $pugoAddressData */
331332
$pugoAddressData = $xml->atBpost->pugoAddress->children(
332-
'http://schema.post.be/shm/deepintegration/v3/common'
333+
Bpost::NS_V3_COMMON
333334
);
334335
$atBpost->setPugoAddress(
335336
PugoAddress::createFromXML($pugoAddressData)

src/Bpost/Order/Box/AtHome.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\Order\Box;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Bpost\Order\Receiver;
67
use Bpost\BpostApiClient\Bpost\ProductConfiguration\Product;
78
use Bpost\BpostApiClient\Common\XmlHelper;
@@ -159,7 +160,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul
159160
if (isset($atHomeXml->receiver)) {
160161
$self->setReceiver(
161162
Receiver::createFromXML(
162-
$atHomeXml->receiver->children('http://schema.post.be/shm/deepintegration/v3/common')
163+
$atHomeXml->receiver->children(Bpost::NS_V3_COMMON)
163164
)
164165
);
165166
}

src/Bpost/Order/Box/AtIntlPugo.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Bpost\BpostApiClient\Bpost\Order\Box;
33

4+
use Bpost\BpostApiClient\Bpost;
45
use Bpost\BpostApiClient\Bpost\Order\Box\National\ShopHandlingInstruction;
56
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging;
67
use Bpost\BpostApiClient\Bpost\Order\PugoAddress;
@@ -252,7 +253,7 @@ public static function createFromXML(\SimpleXMLElement $xml)
252253
if (isset($xml->atIntlPugo->options)) {
253254
/** @var \SimpleXMLElement $optionData */
254255
foreach ($xml->atIntlPugo->options as $optionData) {
255-
$optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
256+
$optionData = $optionData->children(Bpost::NS_V3_COMMON);
256257

257258
if (in_array(
258259
$optionData->getName(),
@@ -288,7 +289,7 @@ public static function createFromXML(\SimpleXMLElement $xml)
288289
if (isset($xml->atIntlPugo->receiver) && $xml->atIntlPugo->receiver != '') {
289290
$self->setReceiver(
290291
Receiver::createFromXML(
291-
$xml->atIntlPugo->receiver->children('http://schema.post.be/shm/deepintegration/v3/common')
292+
$xml->atIntlPugo->receiver->children(Bpost::NS_V3_COMMON)
292293
)
293294
);
294295
}
@@ -304,9 +305,7 @@ public static function createFromXML(\SimpleXMLElement $xml)
304305
}
305306
if (isset($xml->atIntlPugo->pugoAddress)) {
306307
/** @var \SimpleXMLElement $pugoAddressData */
307-
$pugoAddressData = $xml->atIntlPugo->pugoAddress->children(
308-
'http://schema.post.be/shm/deepintegration/v3/common'
309-
);
308+
$pugoAddressData = $xml->atIntlPugo->pugoAddress->children(Bpost::NS_V3_COMMON);
310309
$self->setPugoAddress(
311310
PugoAddress::createFromXML($pugoAddressData)
312311
);

src/Bpost/Order/Box/BpostOnAppointment.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bpost\BpostApiClient\Bpost\Order\Box;
44

5+
use Bpost\BpostApiClient\Bpost;
56
use Bpost\BpostApiClient\Bpost\Order\Receiver;
67
use Bpost\BpostApiClient\Common\XmlHelper;
78
use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException;
@@ -125,7 +126,7 @@ public static function createFromXML(SimpleXMLElement $xml, National $self = nul
125126
if (isset($bpostOnAppointmentXml->receiver)) {
126127
$self->setReceiver(
127128
Receiver::createFromXML(
128-
$bpostOnAppointmentXml->receiver->children('http://schema.post.be/shm/deepintegration/v3/common')
129+
$bpostOnAppointmentXml->receiver->children(Bpost::NS_V3_COMMON)
129130
)
130131
);
131132
}

0 commit comments

Comments
 (0)