|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 1998-2015 Browser Capabilities Project |
|
4
|
|
|
* |
|
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
|
6
|
|
|
* copy of this software and associated documentation files (the "Software"), |
|
7
|
|
|
* to deal in the Software without restriction, including without limitation |
|
8
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
9
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the |
|
10
|
|
|
* Software is furnished to do so, subject to the following conditions: |
|
11
|
|
|
* |
|
12
|
|
|
* The above copyright notice and this permission notice shall be included |
|
13
|
|
|
* in all copies or substantial portions of the Software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
16
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
21
|
|
|
* THE SOFTWARE. |
|
22
|
|
|
* |
|
23
|
|
|
* @category Browscap-PHP |
|
24
|
|
|
* @copyright 1998-2015 Browser Capabilities Project |
|
25
|
|
|
* @license http://www.opensource.org/licenses/MIT MIT License |
|
26
|
|
|
* @link https://github.com/browscap/browscap-php/ |
|
27
|
|
|
* @since added with version 3.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
namespace BrowscapPHP\Formatter; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* formatter to output the data like the native get_browser function |
|
34
|
|
|
* |
|
35
|
|
|
* @category Browscap-PHP |
|
36
|
|
|
* @author Christoph Ziegenberg <[email protected]> |
|
37
|
|
|
* @author Thomas Müller <[email protected]> |
|
38
|
|
|
* @copyright Copyright (c) 1998-2015 Browser Capabilities Project |
|
39
|
|
|
* @version 3.0 |
|
40
|
|
|
* @license http://www.opensource.org/licenses/MIT MIT License |
|
41
|
|
|
* @link https://github.com/browscap/browscap-php/ |
|
42
|
|
|
*/ |
|
43
|
|
|
class PhpGetBrowser implements FormatterInterface |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* Variable to save the settings in, type depends on implementation |
|
47
|
|
|
* |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
private $settings = []; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* a list of possible properties |
|
54
|
|
|
* |
|
55
|
|
|
* @var array |
|
56
|
|
|
*/ |
|
57
|
|
|
private $defaultproperties = [ |
|
58
|
|
|
'browser_name_regex' => null, |
|
59
|
|
|
'browser_name_pattern' => null, |
|
60
|
|
|
'Parent' => null, |
|
61
|
|
|
'Comment' => 'Default Browser', |
|
62
|
|
|
'Browser' => 'Default Browser', |
|
63
|
|
|
'Browser_Type' => 'unknown', |
|
64
|
|
|
'Browser_Bits' => '0', |
|
65
|
|
|
'Browser_Maker' => 'unknown', |
|
66
|
|
|
'Browser_Modus' => 'unknown', |
|
67
|
|
|
'Version' => '0.0', |
|
68
|
|
|
'MajorVer' => '0', |
|
69
|
|
|
'MinorVer' => '0', |
|
70
|
|
|
'Platform' => 'unknown', |
|
71
|
|
|
'Platform_Version' => 'unknown', |
|
72
|
|
|
'Platform_Description' => 'unknown', |
|
73
|
|
|
'Platform_Bits' => '0', |
|
74
|
|
|
'Platform_Maker' => 'unknown', |
|
75
|
|
|
'Alpha' => 'false', |
|
76
|
|
|
'Beta' => 'false', |
|
77
|
|
|
'Win16' => 'false', |
|
78
|
|
|
'Win32' => 'false', |
|
79
|
|
|
'Win64' => 'false', |
|
80
|
|
|
'Frames' => 'false', |
|
81
|
|
|
'IFrames' => 'false', |
|
82
|
|
|
'Tables' => 'false', |
|
83
|
|
|
'Cookies' => 'false', |
|
84
|
|
|
'BackgroundSounds' => 'false', |
|
85
|
|
|
'JavaScript' => 'false', |
|
86
|
|
|
'VBScript' => 'false', |
|
87
|
|
|
'JavaApplets' => 'false', |
|
88
|
|
|
'ActiveXControls' => 'false', |
|
89
|
|
|
'isMobileDevice' => 'false', |
|
90
|
|
|
'isTablet' => 'false', |
|
91
|
|
|
'isSyndicationReader' => 'false', |
|
92
|
|
|
'Crawler' => 'false', |
|
93
|
|
|
'isFake' => 'false', |
|
94
|
|
|
'isAnonymized' => 'false', |
|
95
|
|
|
'isModified' => 'false', |
|
96
|
|
|
'CssVersion' => '0', |
|
97
|
|
|
'AolVersion' => '0', |
|
98
|
|
|
'Device_Name' => 'unknown', |
|
99
|
|
|
'Device_Maker' => 'unknown', |
|
100
|
|
|
'Device_Type' => 'unknown', |
|
101
|
|
|
'Device_Pointing_Method' => 'unknown', |
|
102
|
|
|
'Device_Code_Name' => 'unknown', |
|
103
|
|
|
'Device_Brand_Name' => 'unknown', |
|
104
|
|
|
'RenderingEngine_Name' => 'unknown', |
|
105
|
|
|
'RenderingEngine_Version' => 'unknown', |
|
106
|
|
|
'RenderingEngine_Description' => 'unknown', |
|
107
|
|
|
'RenderingEngine_Maker' => 'unknown', |
|
108
|
|
|
]; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Sets the data (done by the parser) |
|
112
|
|
|
* |
|
113
|
|
|
* @param array $settings |
|
114
|
|
|
* |
|
115
|
|
|
* @return \BrowscapPHP\Formatter\PhpGetBrowser |
|
116
|
|
|
*/ |
|
117
|
3 |
|
public function setData(array $settings) |
|
118
|
|
|
{ |
|
119
|
3 |
|
foreach ($settings as $key => $value) { |
|
120
|
3 |
|
$this->settings[strtolower($key)] = $value; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
3 |
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Gets the data (in the preferred format) |
|
128
|
|
|
* |
|
129
|
|
|
* @return \stdClass |
|
130
|
|
|
*/ |
|
131
|
4 |
|
public function getData() |
|
132
|
|
|
{ |
|
133
|
4 |
|
$output = new \stdClass(); |
|
134
|
|
|
|
|
135
|
4 |
|
foreach (array_keys($this->defaultproperties) as $property) { |
|
136
|
4 |
|
$key = strtolower($property); |
|
137
|
|
|
|
|
138
|
4 |
|
if (array_key_exists($key, $this->settings)) { |
|
139
|
3 |
|
$output->$key = $this->settings[$key]; |
|
140
|
4 |
|
} elseif ('parent' !== $key) { |
|
141
|
4 |
|
$output->$key = $this->defaultproperties[$property]; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
// Don't want to normally do this, just if it exists in the data file |
|
146
|
|
|
// for our test runs |
|
147
|
4 |
|
if (array_key_exists('patternid', $this->settings)) { |
|
148
|
1 |
|
$output->patternid = $this->settings['patternid']; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
4 |
|
return $output; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|