1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace eBayEnterprise\RetailOrderManagement\Payload\Order; |
17
|
|
|
|
18
|
|
|
use BadMethodCallException; |
19
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayload; |
20
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap; |
21
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator; |
22
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator; |
23
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
24
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\TIterablePayload; |
25
|
|
|
use Psr\Log\LoggerInterface; |
26
|
|
|
use Psr\Log\NullLogger; |
27
|
|
|
use SPLObjectStorage; |
28
|
|
|
|
29
|
|
|
class OrderDestinationIterable extends SPLObjectStorage implements IOrderDestinationIterable |
30
|
|
|
{ |
31
|
|
|
use TIterablePayload; |
32
|
|
|
|
33
|
|
|
const SUBPAYLOAD_XPATH = 'x:MailingAddress|x:StoreLocation|x:Email'; |
34
|
|
|
const ROOT_NODE = 'Destinations'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param IValidatorIterator |
38
|
|
|
* @param ISchemaValidator |
39
|
|
|
* @param IPayloadMap |
40
|
|
|
* @param LoggerInterface |
41
|
|
|
* @param IPayload |
42
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
IValidatorIterator $validators, |
46
|
|
|
ISchemaValidator $schemaValidator, |
|
|
|
|
47
|
|
|
IPayloadMap $payloadMap, |
48
|
|
|
LoggerInterface $logger, |
49
|
|
|
IPayload $parentPayload = null |
50
|
|
|
) { |
51
|
|
|
$this->logger = $logger; |
|
|
|
|
52
|
|
|
$this->validators = $validators; |
53
|
|
|
$this->payloadMap = $payloadMap; |
54
|
|
|
$this->parentPayload = $parentPayload; |
55
|
|
|
$this->payloadFactory = new PayloadFactory; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function deserialize($serializedData) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$xpath = $this->getPayloadAsXPath($serializedData); |
61
|
|
|
foreach ($xpath->query($this->getSubpayloadXPath()) as $subpayloadNode) { |
62
|
|
|
switch ($subpayloadNode->nodeName) { |
63
|
|
|
case 'MailingAddress': |
64
|
|
|
$pl = $this->getEmptyMailingAddress(); |
65
|
|
|
break; |
66
|
|
|
case 'StoreLocation': |
67
|
|
|
$pl = $this->getEmptyStoreLocation(); |
68
|
|
|
break; |
69
|
|
|
case 'Email': |
70
|
|
|
$pl = $this->getEmptyEmailAddress(); |
71
|
|
|
break; |
72
|
|
|
} |
73
|
|
|
if (isset($pl)) { |
74
|
|
|
$pl->deserialize($subpayloadNode->C14N()); |
75
|
|
|
$this->offsetSet($pl); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
$this->validate(); |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
protected function serializeContents() |
83
|
|
|
{ |
84
|
|
|
// Destinations must be ordered by type. Build out three separate |
85
|
|
|
// serializations, one for each type, to keep destinations of a certain |
86
|
|
|
// type together. |
87
|
|
|
$mailingDestinations = ''; |
88
|
|
|
$storeLocations = ''; |
89
|
|
|
$emailDestinations = ''; |
90
|
|
|
foreach ($this as $destination) { |
91
|
|
|
if ($destination instanceof IEmailAddressDestination) { |
92
|
|
|
$emailDestinations .= $destination->serialize(); |
93
|
|
|
} elseif ($destination instanceof IStoreLocation) { |
94
|
|
|
$storeLocations .= $destination->serialize(); |
95
|
|
|
} else { |
96
|
|
|
$mailingDestinations .= $destination->serialize(); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
// Concatenate the serializations together in the required order. |
100
|
|
|
return $mailingDestinations . $storeLocations . $emailDestinations; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getNewSubpayload() |
104
|
|
|
{ |
105
|
|
|
throw new BadMethodCallException('Method not supported for this type.'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get a new, empty mailing address destination object. |
110
|
|
|
* |
111
|
|
|
* @return IMailingAddress |
112
|
|
|
*/ |
113
|
|
|
public function getEmptyMailingAddress() |
114
|
|
|
{ |
115
|
|
|
return $this->buildPayloadForInterface(static::MAILING_ADDRESS_INTERFACE); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get a new, empty store location destination object. |
120
|
|
|
* |
121
|
|
|
* @return IStoreLocation |
122
|
|
|
*/ |
123
|
|
|
public function getEmptyStoreLocation() |
124
|
|
|
{ |
125
|
|
|
return $this->buildPayloadForInterface(static::STORE_LOCATION_INTERFACE); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get a new, empty email address destination object. |
130
|
|
|
* |
131
|
|
|
* @return IEmailAddressDestination |
132
|
|
|
*/ |
133
|
|
|
public function getEmptyEmailAddress() |
134
|
|
|
{ |
135
|
|
|
return $this->buildPayloadForInterface(static::EMAIL_ADDRESS_INTERFACE); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getSubpayloadXPath() |
139
|
|
|
{ |
140
|
|
|
return static::SUBPAYLOAD_XPATH; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getRootNodeName() |
144
|
|
|
{ |
145
|
|
|
return static::ROOT_NODE; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getXmlNamespace() |
149
|
|
|
{ |
150
|
|
|
return self::XML_NS; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.