|
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-2015 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\Detail; |
|
17
|
|
|
|
|
18
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayload; |
|
19
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap; |
|
20
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator; |
|
21
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator; |
|
22
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\TTopLevelPayload; |
|
23
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
|
24
|
|
|
use Psr\Log\LoggerInterface; |
|
25
|
|
|
use Psr\Log\NullLogger; |
|
26
|
|
|
|
|
27
|
|
|
class OrderDetailResponse implements IOrderDetailResponse |
|
28
|
|
|
{ |
|
29
|
|
|
use TTopLevelPayload; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
protected $orderType; |
|
33
|
|
|
/** @var string */ |
|
34
|
|
|
protected $testType; |
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
protected $cancellable; |
|
37
|
|
|
/** @var IOrderResponse */ |
|
38
|
|
|
protected $order; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param IValidatorIterator |
|
42
|
|
|
* @param ISchemaValidator |
|
43
|
|
|
* @param IPayloadMap |
|
44
|
|
|
* @param LoggerInterface |
|
45
|
|
|
* @param IPayload |
|
46
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
IValidatorIterator $validators, |
|
50
|
|
|
ISchemaValidator $schemaValidator, |
|
51
|
|
|
IPayloadMap $payloadMap, |
|
52
|
|
|
LoggerInterface $logger, |
|
53
|
|
|
IPayload $parentPayload = null |
|
54
|
|
|
) { |
|
55
|
|
|
$this->logger = $logger; |
|
|
|
|
|
|
56
|
|
|
$this->validators = $validators; |
|
57
|
|
|
$this->schemaValidator = $schemaValidator; |
|
58
|
|
|
$this->parentPayload = $parentPayload; |
|
59
|
|
|
$this->payloadMap = $payloadMap; |
|
60
|
|
|
$this->payloadFactory = $this->getNewPayloadFactory(); |
|
61
|
|
|
|
|
62
|
|
|
$this->initExtractPaths() |
|
63
|
|
|
->initOptionalExtractPaths() |
|
64
|
|
|
->initSubPayloadExtractPaths() |
|
65
|
|
|
->initSubPayloadProperties(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Initialize the protected class property array self::extractionPaths with xpath |
|
70
|
|
|
* key/value pairs. |
|
71
|
|
|
* |
|
72
|
|
|
* @return self |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function initExtractPaths() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->extractionPaths = [ |
|
77
|
|
|
'orderType' => 'string(@orderType)', |
|
78
|
|
|
'cancellable' => 'string(@cancellable)', |
|
79
|
|
|
]; |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Initialize the protected class property array self::optionalExtractionPaths with xpath |
|
85
|
|
|
* key/value pairs. |
|
86
|
|
|
* |
|
87
|
|
|
* @return self |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function initOptionalExtractPaths() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->optionalExtractionPaths = [ |
|
92
|
|
|
'testType' => '@testType', |
|
93
|
|
|
]; |
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Initialize the protected class property array self::subpayloadExtractionPaths with xpath |
|
99
|
|
|
* key/value pairs. |
|
100
|
|
|
* |
|
101
|
|
|
* @return self |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function initSubPayloadExtractPaths() |
|
104
|
|
|
{ |
|
105
|
|
|
$this->subpayloadExtractionPaths = [ |
|
106
|
|
|
'order' => 'x:Order', |
|
107
|
|
|
]; |
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Initialize any sub-payload class properties with their concrete instance. |
|
113
|
|
|
* |
|
114
|
|
|
* @return self |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function initSubPayloadProperties() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->setOrder($this->buildPayloadForInterface( |
|
|
|
|
|
|
119
|
|
|
static::ORDER_RESPONSE_INTERFACE |
|
120
|
|
|
)); |
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @see IOrderDetailResponse::getOrderType() |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getOrderType() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->orderType; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @see IOrderDetailResponse::setOrderType() |
|
134
|
|
|
* @codeCoverageIgnore |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setOrderType($orderType) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->orderType = $orderType; |
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @see IOrderDetailResponse::getTestType() |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getTestType() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->testType; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @see IOrderDetailResponse::setTestType() |
|
152
|
|
|
* @codeCoverageIgnore |
|
153
|
|
|
*/ |
|
154
|
|
|
public function setTestType($testType) |
|
155
|
|
|
{ |
|
156
|
|
|
$this->testType = $testType; |
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @see IOrderDetailResponse::getCancellable() |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getCancellable() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->cancellable; |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @see IOrderDetailResponse::setCancellable() |
|
170
|
|
|
* @codeCoverageIgnore |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setCancellable($cancellable) |
|
173
|
|
|
{ |
|
174
|
|
|
$this->cancellable = $cancellable; |
|
175
|
|
|
return $this; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @see IOrderDetailResponse::getOrder() |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getOrder() |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->order; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @see IOrderDetailResponse::setOrder() |
|
188
|
|
|
* @codeCoverageIgnore |
|
189
|
|
|
*/ |
|
190
|
|
|
public function setOrder(IOrderResponse $order) |
|
191
|
|
|
{ |
|
192
|
|
|
$this->order = $order; |
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @see TPayload::serializeContents() |
|
198
|
|
|
*/ |
|
199
|
|
|
protected function serializeContents() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->getOrder()->serialize(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @see TPayload::getRootNodeName() |
|
206
|
|
|
*/ |
|
207
|
|
|
protected function getRootNodeName() |
|
208
|
|
|
{ |
|
209
|
|
|
return static::ROOT_NODE; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @see TPayload::getXmlNamespace() |
|
214
|
|
|
*/ |
|
215
|
|
|
protected function getXmlNamespace() |
|
216
|
|
|
{ |
|
217
|
|
|
return self::XML_NS; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
protected function getSchemaFile() |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->getSchemaDir() . self::XSD; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Validate the serialized data via the schema validator. |
|
227
|
|
|
* @param string |
|
228
|
|
|
* @return self |
|
229
|
|
|
*/ |
|
230
|
|
|
protected function schemaValidate($serializedData) |
|
231
|
|
|
{ |
|
232
|
|
|
$this->schemaValidator->validate($serializedData, $this->getSchemaFile()); |
|
233
|
|
|
return $this; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @see TPayload::getRootAttributes() |
|
238
|
|
|
*/ |
|
239
|
|
|
protected function getRootAttributes() |
|
240
|
|
|
{ |
|
241
|
|
|
$testType = $this->getTestType(); |
|
242
|
|
|
return array_merge( |
|
243
|
|
|
['xmlns' => $this->getXmlNamespace(), 'orderType' => $this->getOrderType()], |
|
244
|
|
|
$testType ? ['testType' => $testType] : [], |
|
245
|
|
|
['cancellable' => $this->getCancellable()] |
|
246
|
|
|
); |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..