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\OrderEvents; |
17
|
|
|
|
18
|
|
|
use DateTime; |
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 Psr\Log\LoggerInterface; |
25
|
|
|
use Psr\Log\NullLogger; |
26
|
|
|
|
27
|
|
|
class EddMessage implements IEddMessage |
28
|
|
|
{ |
29
|
|
|
use TPayload, TDeliveryWindow; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $mode; |
33
|
|
|
/** @var string */ |
34
|
|
|
protected $messageType; |
35
|
|
|
/** @var string */ |
36
|
|
|
protected $template; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param IValidatorIterator |
40
|
|
|
* @param ISchemaValidator |
41
|
|
|
* @param IPayloadMap |
42
|
|
|
* @param LoggerInterface |
43
|
|
|
* @param IPayload |
44
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
IValidatorIterator $validators, |
48
|
|
|
ISchemaValidator $schemaValidator, |
|
|
|
|
49
|
|
|
IPayloadMap $payloadMap, |
|
|
|
|
50
|
|
|
LoggerInterface $logger, |
51
|
|
|
IPayload $parentPayload = null |
52
|
|
|
) { |
53
|
|
|
$this->logger = $logger; |
|
|
|
|
54
|
|
|
$this->validators = $validators; |
55
|
|
|
$this->parentPayload = $parentPayload; |
56
|
|
|
|
57
|
|
|
$this->extractionPaths = [ |
58
|
|
|
'mode' => 'string(x:Mode)', |
59
|
|
|
'messageType' => 'string(x:MessageType)', |
60
|
|
|
'template' => 'string(x:Template)', |
61
|
|
|
]; |
62
|
|
|
$this->optionalExtractionPaths = [ |
63
|
|
|
'to' => 'x:DeliveryWindow/x:To', |
64
|
|
|
'from' => 'x:DeliveryWindow/x:From', |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string |
70
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
71
|
|
|
*/ |
72
|
|
|
protected function deserializeExtra($serializedPayload) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$from = $this->getFrom(); |
75
|
|
|
$to = $this->getTo(); |
76
|
|
|
if (!$from instanceof DateTime && !empty($from) && is_string($from)) { |
77
|
|
|
$this->setFrom($from); |
78
|
|
|
} |
79
|
|
|
if (!$to instanceof DateTime && !empty($to) && is_string($to)) { |
80
|
|
|
$this->setTo($to); |
81
|
|
|
} |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getMode() |
86
|
|
|
{ |
87
|
|
|
return $this->mode; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function setMode($mode) |
91
|
|
|
{ |
92
|
|
|
$this->mode = $mode; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getMessageType() |
97
|
|
|
{ |
98
|
|
|
return $this->messageType; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setMessageType($messageType) |
102
|
|
|
{ |
103
|
|
|
$this->messageType = $messageType; |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getTemplate() |
108
|
|
|
{ |
109
|
|
|
return $this->template; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function setTemplate($template) |
113
|
|
|
{ |
114
|
|
|
$this->template = $template; |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
protected function getRootNodeName() |
119
|
|
|
{ |
120
|
|
|
return static::ROOT_NODE; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function getRootAttributes() |
124
|
|
|
{ |
125
|
|
|
return []; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected function serializeContents() |
129
|
|
|
{ |
130
|
|
|
return $this->serializeMode() |
131
|
|
|
. $this->serializeMessageType() |
132
|
|
|
. $this->serializeTemplate() |
133
|
|
|
. $this->serializeDeliveryWindow(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
protected function serializeMode() |
137
|
|
|
{ |
138
|
|
|
$mode = $this->getMode(); |
139
|
|
|
return (!empty($mode) && is_string($mode)) |
140
|
|
|
? "<Mode>$mode</Mode>" : ''; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
protected function serializeMessageType() |
144
|
|
|
{ |
145
|
|
|
$messageType = $this->getMessageType(); |
146
|
|
|
return (!empty($messageType) && is_string($messageType)) |
147
|
|
|
? "<MessageType>$messageType</MessageType>" : ''; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
protected function serializeTemplate() |
151
|
|
|
{ |
152
|
|
|
$template = $this->getTemplate(); |
153
|
|
|
return (!empty($template) && is_string($template)) |
154
|
|
|
? "<Template>$template</Template>" : ''; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
protected function getXmlNamespace() |
158
|
|
|
{ |
159
|
|
|
return self::XML_NS; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.