1 | <?php |
||
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() |
||
59 | |||
60 | public function setHostname($hostname) |
||
61 | { |
||
62 | $this->hostname = $this->cleanString($hostname, 50); |
||
|
|||
63 | return $this; |
||
64 | } |
||
65 | |||
66 | public function getIpAddress() |
||
70 | |||
71 | public function setIpAddress($ipAddress) |
||
72 | { |
||
73 | $this->ipAddress = $this->isValidIpAddress($ipAddress) ? $ipAddress : null; |
||
74 | return $this; |
||
75 | } |
||
76 | |||
77 | public function getSessionId() |
||
81 | |||
82 | public function setSessionId($sessionId) |
||
83 | { |
||
84 | $this->sessionId = $this->cleanString($sessionId, 255); |
||
85 | return $this; |
||
86 | } |
||
87 | |||
88 | public function getUserAgent() |
||
92 | |||
93 | public function setUserAgent($userAgent) |
||
94 | { |
||
95 | $this->userAgent = $this->cleanString($userAgent, 4096); |
||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | public function getConnection() |
||
103 | |||
104 | public function setConnection($connection) |
||
105 | { |
||
106 | $this->connection = $this->cleanString($connection, 25); |
||
107 | return $this; |
||
108 | } |
||
109 | |||
110 | public function getCookies() |
||
114 | |||
115 | public function setCookies($cookies) |
||
116 | { |
||
117 | $this->cookies = $this->normalizeWhitespace($cookies); |
||
118 | return $this; |
||
119 | } |
||
120 | |||
121 | public function getUserCookie() |
||
125 | |||
126 | public function setUserCookie($userCookie) |
||
127 | { |
||
128 | $this->userCookie = $this->cleanString($userCookie, 50); |
||
129 | return $this; |
||
130 | } |
||
131 | |||
132 | public function getUserAgentOs() |
||
136 | |||
137 | public function setUserAgentOs($userAgentOs) |
||
138 | { |
||
139 | $this->userAgentOs = $this->cleanString($userAgentOs, 100); |
||
140 | return $this; |
||
141 | } |
||
142 | |||
143 | public function getUserAgentCpu() |
||
147 | |||
148 | public function setUserAgentCpu($userAgentCpu) |
||
149 | { |
||
150 | $this->userAgentCpu = $this->cleanString($userAgentCpu, 100); |
||
151 | return $this; |
||
152 | } |
||
153 | |||
154 | public function getHeaderFrom() |
||
158 | |||
159 | public function setHeaderFrom($headerFrom) |
||
160 | { |
||
161 | $this->headerFrom = $this->cleanString($headerFrom, 100); |
||
162 | return $this; |
||
163 | } |
||
164 | |||
165 | public function getWebBrowserName() |
||
169 | |||
170 | public function setWebBrowserName($webBrowserName) |
||
171 | { |
||
172 | $this->webBrowserName = $this->cleanString($webBrowserName, 100); |
||
173 | return $this; |
||
174 | } |
||
175 | |||
176 | public function getJavascriptData() |
||
180 | |||
181 | public function setJavascriptData($javascriptData) |
||
182 | { |
||
183 | $this->javascriptData = $this->normalizeWhitespace($javascriptData); |
||
184 | return $this; |
||
185 | } |
||
186 | |||
187 | public function getReferrer() |
||
191 | |||
192 | public function setReferrer($referrer) |
||
193 | { |
||
194 | $this->referrer = $this->cleanString($referrer, 1024); |
||
195 | return $this; |
||
196 | } |
||
197 | |||
198 | public function getContentTypes() |
||
202 | |||
203 | public function setContentTypes($contentTypes) |
||
204 | { |
||
205 | $this->contentTypes = $this->cleanString($contentTypes, 1024); |
||
206 | return $this; |
||
207 | } |
||
208 | |||
209 | public function getEncoding() |
||
213 | |||
214 | public function setEncoding($encoding) |
||
215 | { |
||
216 | $this->encoding = $this->cleanString($encoding, 50); |
||
217 | return $this; |
||
218 | } |
||
219 | |||
220 | public function getLanguage() |
||
224 | |||
225 | public function setLanguage($language) |
||
226 | { |
||
227 | $this->language = $this->cleanString($language, 255); |
||
228 | return $this; |
||
229 | } |
||
230 | |||
231 | public function getCharSet() |
||
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) |
||
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
Idable
provides a methodequalsId
that 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.