|
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; |
|
17
|
|
|
|
|
18
|
|
|
trait TBrowserData |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
protected $hostname; |
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $ipAddress; |
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
protected $sessionId; |
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $userAgent; |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $connection; |
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
protected $cookies; |
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
protected $userCookie; |
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
protected $userAgentOs; |
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
protected $userAgentCpu; |
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
protected $headerFrom; |
|
40
|
|
|
/** @var string */ |
|
41
|
|
|
protected $webBrowserName; |
|
42
|
|
|
/** @var string */ |
|
43
|
|
|
protected $javascriptData; |
|
44
|
|
|
/** @var string */ |
|
45
|
|
|
protected $referrer; |
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
protected $contentTypes; |
|
48
|
|
|
/** @var string */ |
|
49
|
|
|
protected $encoding; |
|
50
|
|
|
/** @var string */ |
|
51
|
|
|
protected $language; |
|
52
|
|
|
/** @var string */ |
|
53
|
|
|
protected $charSet; |
|
54
|
|
|
|
|
55
|
|
|
public function getHostname() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->hostname; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function setHostname($hostname) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->hostname = $this->cleanString($hostname, 50); |
|
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getIpAddress() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->ipAddress; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function setIpAddress($ipAddress) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->ipAddress = $this->isValidIpAddress($ipAddress) ? $ipAddress : null; |
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getSessionId() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->sessionId; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setSessionId($sessionId) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->sessionId = $this->cleanString($sessionId, 255); |
|
|
|
|
|
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getUserAgent() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->userAgent; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function setUserAgent($userAgent) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->userAgent = $this->cleanString($userAgent, 4096); |
|
|
|
|
|
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getConnection() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->connection; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function setConnection($connection) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->connection = $this->cleanString($connection, 25); |
|
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getCookies() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->cookies; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function setCookies($cookies) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->cookies = $this->normalizeWhitespace($cookies); |
|
|
|
|
|
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function getUserCookie() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->userCookie; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function setUserCookie($userCookie) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->userCookie = $this->cleanString($userCookie, 50); |
|
|
|
|
|
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getUserAgentOs() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->userAgentOs; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function setUserAgentOs($userAgentOs) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->userAgentOs = $this->cleanString($userAgentOs, 100); |
|
|
|
|
|
|
140
|
|
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getUserAgentCpu() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->userAgentCpu; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function setUserAgentCpu($userAgentCpu) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->userAgentCpu = $this->cleanString($userAgentCpu, 100); |
|
|
|
|
|
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function getHeaderFrom() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->headerFrom; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function setHeaderFrom($headerFrom) |
|
160
|
|
|
{ |
|
161
|
|
|
$this->headerFrom = $this->cleanString($headerFrom, 100); |
|
|
|
|
|
|
162
|
|
|
return $this; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function getWebBrowserName() |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->webBrowserName; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function setWebBrowserName($webBrowserName) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->webBrowserName = $this->cleanString($webBrowserName, 100); |
|
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function getJavascriptData() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->javascriptData; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function setJavascriptData($javascriptData) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->javascriptData = $this->normalizeWhitespace($javascriptData); |
|
|
|
|
|
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function getReferrer() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->referrer; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function setReferrer($referrer) |
|
193
|
|
|
{ |
|
194
|
|
|
$this->referrer = $this->cleanString($referrer, 1024); |
|
|
|
|
|
|
195
|
|
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function getContentTypes() |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->contentTypes; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function setContentTypes($contentTypes) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->contentTypes = $this->cleanString($contentTypes, 1024); |
|
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function getEncoding() |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->encoding; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function setEncoding($encoding) |
|
215
|
|
|
{ |
|
216
|
|
|
$this->encoding = $this->cleanString($encoding, 50); |
|
|
|
|
|
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function getLanguage() |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->language; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public function setLanguage($language) |
|
226
|
|
|
{ |
|
227
|
|
|
$this->language = $this->cleanString($language, 255); |
|
|
|
|
|
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
public function getCharSet() |
|
232
|
|
|
{ |
|
233
|
|
|
return $this->charSet; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
public function setCharSet($charSet) |
|
237
|
|
|
{ |
|
238
|
|
|
$this->charSet = $this->cleanString($charSet, 50); |
|
|
|
|
|
|
239
|
|
|
return $this; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Serialize browser data associated with the order. |
|
244
|
|
|
* |
|
245
|
|
|
* @return string |
|
246
|
|
|
*/ |
|
247
|
|
|
protected function serializeBrowserData() |
|
248
|
|
|
{ |
|
249
|
|
|
return '<BrowserData>' |
|
250
|
|
|
. "<HostName>{$this->xmlEncode($this->getHostname())}</HostName>" |
|
251
|
|
|
. "<IPAddress>{$this->xmlEncode($this->getIpAddress())}</IPAddress>" |
|
252
|
|
|
. '<SessionId>' . $this->xmlEncode($this->getSessionId()) . '</SessionId>' |
|
253
|
|
|
. '<UserAgent>' . $this->xmlEncode($this->getUserAgent()) . '</UserAgent>' |
|
254
|
|
|
. $this->serializeOptionalXmlEncodedValue('Connection', $this->getConnection()) |
|
255
|
|
|
. $this->serializeOptionalXmlEncodedValue('Cookies', $this->getCookies()) |
|
256
|
|
|
. $this->serializeOptionalXmlEncodedValue('UserCookie', $this->getUserCookie()) |
|
257
|
|
|
. $this->serializeOptionalXmlEncodedValue('UserAgentOS', $this->getUserAgentOs()) |
|
258
|
|
|
. $this->serializeOptionalXmlEncodedValue('UserAgentCPU', $this->getUserAgentCpu()) |
|
259
|
|
|
. $this->serializeOptionalXmlEncodedValue('HeaderFrom', $this->getHeaderFrom()) |
|
260
|
|
|
. $this->serializeOptionalXmlEncodedValue('EmbeddedWebBrowserFrom', $this->getWebBrowserName()) |
|
261
|
|
|
. '<JavascriptData>' . $this->xmlEncode($this->getJavascriptData()) . '</JavascriptData>' |
|
262
|
|
|
. '<Referrer>' . $this->xmlEncode($this->getReferrer()) . '</Referrer>' |
|
263
|
|
|
. "<HTTPAcceptData>" |
|
264
|
|
|
. '<ContentTypes>' . $this->xmlEncode($this->getContentTypes()) . '</ContentTypes>' |
|
265
|
|
|
. '<Encoding>' . $this->xmlEncode($this->getEncoding()) . '</Encoding>' |
|
266
|
|
|
. "<Language>{$this->xmlEncode($this->getLanguage())}</Language>" |
|
267
|
|
|
. '<CharSet>' . $this->xmlEncode($this->getCharSet()) . '</CharSet>' |
|
268
|
|
|
. "</HTTPAcceptData>" |
|
269
|
|
|
. '</BrowserData>'; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Test for an IP address to be a valid IP address. Currently, requires |
|
274
|
|
|
* address to be valid IPv4 addresses only. |
|
275
|
|
|
* |
|
276
|
|
|
* @param string |
|
277
|
|
|
* @return bool |
|
278
|
|
|
*/ |
|
279
|
|
|
protected function isValidIpAddress($ipAddress) |
|
280
|
|
|
{ |
|
281
|
|
|
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Serialize an optional element containing a string. The value will be |
|
286
|
|
|
* xml-encoded if is not null. |
|
287
|
|
|
* |
|
288
|
|
|
* @param string |
|
289
|
|
|
* @param string |
|
290
|
|
|
* @return string |
|
291
|
|
|
*/ |
|
292
|
|
|
abstract protected function serializeOptionalXmlEncodedValue($name, $value); |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* encode the passed in string to be safe for xml if it is not null, |
|
296
|
|
|
* otherwise simply return the null parameter. |
|
297
|
|
|
* |
|
298
|
|
|
* @param string|null |
|
299
|
|
|
* @return string|null |
|
300
|
|
|
*/ |
|
301
|
|
|
abstract protected function xmlEncode($value = null); |
|
302
|
|
|
} |
|
303
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.