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\Order\TOrderCustomer; |
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\TPayload; |
24
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
25
|
|
|
use Psr\Log\LoggerInterface; |
26
|
|
|
use Psr\Log\NullLogger; |
27
|
|
|
|
28
|
|
|
class OrderDetailCustomer implements IOrderDetailCustomer |
29
|
|
|
{ |
30
|
|
|
use TPayload, TOrderCustomer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param IValidatorIterator |
34
|
|
|
* @param ISchemaValidator |
35
|
|
|
* @param IPayloadMap |
36
|
|
|
* @param LoggerInterface |
37
|
|
|
* @param IPayload |
38
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
IValidatorIterator $validators, |
42
|
|
|
ISchemaValidator $schemaValidator, |
43
|
|
|
IPayloadMap $payloadMap, |
44
|
|
|
LoggerInterface $logger, |
45
|
|
|
IPayload $parentPayload = null |
46
|
|
|
) { |
47
|
|
|
$this->logger = $logger; |
|
|
|
|
48
|
|
|
$this->validators = $validators; |
49
|
|
|
$this->schemaValidator = $schemaValidator; |
50
|
|
|
$this->parentPayload = $parentPayload; |
51
|
|
|
$this->payloadMap = $payloadMap; |
52
|
|
|
$this->payloadFactory = $this->getNewPayloadFactory(); |
53
|
|
|
|
54
|
|
|
$this->initExtractPaths() |
55
|
|
|
->initOptionalExtractPaths() |
56
|
|
|
->initBooleanExtractPaths() |
57
|
|
|
->initDatetimeExtractPaths() |
58
|
|
|
->initSubPayloadExtractPaths() |
59
|
|
|
->initSubPayloadProperties(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initialize the protected class property array self::extractionPaths with xpath |
64
|
|
|
* key/value pairs. |
65
|
|
|
* |
66
|
|
|
* @return self |
67
|
|
|
*/ |
68
|
|
|
protected function initExtractPaths() |
69
|
|
|
{ |
70
|
|
|
$this->extractionPaths = [ |
71
|
|
|
'firstName' => 'string(x:Name/x:FirstName)', |
72
|
|
|
'lastName' => 'string(x:Name/x:LastName)', |
73
|
|
|
]; |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Initialize the protected class property array self::optionalExtractionPaths with xpath |
79
|
|
|
* key/value pairs. |
80
|
|
|
* |
81
|
|
|
* @return self |
82
|
|
|
*/ |
83
|
|
|
protected function initOptionalExtractPaths() |
84
|
|
|
{ |
85
|
|
|
$this->optionalExtractionPaths = [ |
86
|
|
|
'customerId' => '@customerId', |
87
|
|
|
'gender' => 'x:Gender', |
88
|
|
|
'emailAddress' => 'x:EmailAddress', |
89
|
|
|
'taxId' => 'x:CustomerTaxId', |
90
|
|
|
'middleName' => 'x:Name/x:MiddleName', |
91
|
|
|
'honorificName' => 'x:Name/x:Honorific', |
92
|
|
|
]; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Initialize the protected class property array self::booleanExtractionPaths with xpath |
98
|
|
|
* key/value pairs. |
99
|
|
|
* |
100
|
|
|
* @return self |
101
|
|
|
*/ |
102
|
|
|
protected function initBooleanExtractPaths() |
103
|
|
|
{ |
104
|
|
|
$this->booleanExtractionPaths = [ |
105
|
|
|
'taxExempt' => 'string(x:TaxExemptFlag)', |
106
|
|
|
]; |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Initialize the protected class property array self::datetimeExtractionPaths with xpath |
112
|
|
|
* key/value pairs. |
113
|
|
|
* |
114
|
|
|
* @return self |
115
|
|
|
*/ |
116
|
|
|
protected function initDatetimeExtractPaths() |
117
|
|
|
{ |
118
|
|
|
$this->datetimeExtractionPaths = [ |
119
|
|
|
'dateOfBirth' => 'string(x:DateOfBirth)', |
120
|
|
|
]; |
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Initialize the protected class property array self::subpayloadExtractionPaths with xpath |
126
|
|
|
* key/value pairs. |
127
|
|
|
* |
128
|
|
|
* @return self |
129
|
|
|
*/ |
130
|
|
|
protected function initSubPayloadExtractPaths() |
131
|
|
|
{ |
132
|
|
|
$this->subpayloadExtractionPaths = [ |
133
|
|
|
'loyaltyPrograms' => 'x:LoyaltyPrograms', |
134
|
|
|
]; |
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Initialize any sub-payload class properties with their concrete instance. |
140
|
|
|
* |
141
|
|
|
* @return self |
142
|
|
|
*/ |
143
|
|
|
protected function initSubPayloadProperties() |
144
|
|
|
{ |
145
|
|
|
$this->setLoyaltyPrograms($this->buildPayloadForInterface( |
|
|
|
|
146
|
|
|
static::LOYALTY_PROGRAM_ITERABLE_INTERFACE |
147
|
|
|
)); |
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @see TPayload::serializeContents() |
153
|
|
|
*/ |
154
|
|
|
protected function serializeContents() |
155
|
|
|
{ |
156
|
|
|
return $this->serializeOrderDetailCustomer(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Serialize the order detail customer data into a string of XML. |
161
|
|
|
* |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
protected function serializeOrderDetailCustomer() |
165
|
|
|
{ |
166
|
|
|
return $this->serializePersonName() |
167
|
|
|
. $this->serializeOptionalXmlEncodedValue('Gender', $this->getGender()) |
168
|
|
|
. $this->serializeOptionalDateValue('DateOfBirth', 'Y-m-d', $this->getDateOfBirth()) |
169
|
|
|
. $this->serializeOptionalXmlEncodedValue('EmailAddress', $this->getEmailAddress()) |
170
|
|
|
. $this->serializeOptionalXmlEncodedValue('CustomerTaxId', $this->getTaxId()) |
171
|
|
|
. $this->serializeTaxExemptFlag() |
172
|
|
|
. $this->getLoyaltyPrograms()->serialize(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @see TPayload::getRootNodeName() |
177
|
|
|
*/ |
178
|
|
|
protected function getRootNodeName() |
179
|
|
|
{ |
180
|
|
|
return static::ROOT_NODE; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @see TPayload::getXmlNamespace() |
185
|
|
|
*/ |
186
|
|
|
protected function getXmlNamespace() |
187
|
|
|
{ |
188
|
|
|
return self::XML_NS; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
protected function getPersonNameRootNodeName() |
192
|
|
|
{ |
193
|
|
|
return self::PERSON_NAME_ROOT_NODE; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @see TPayload::getRootAttributes() |
198
|
|
|
*/ |
199
|
|
|
protected function getRootAttributes() |
200
|
|
|
{ |
201
|
|
|
$customerId = $this->getCustomerId(); |
202
|
|
|
return $customerId ? ['customerId' => $customerId] : []; |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
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..