1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Platine User Agent |
5
|
|
|
* |
6
|
|
|
* Platine User Agent is a lightweight library for detecting |
7
|
|
|
* user browser, device, OS, CPU |
8
|
|
|
* |
9
|
|
|
* This content is released under the MIT License (MIT) |
10
|
|
|
* |
11
|
|
|
* Copyright (c) 2020 Platine User Agent |
12
|
|
|
* |
13
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
14
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
15
|
|
|
* in the Software without restriction, including without limitation the rights |
16
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
17
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
18
|
|
|
* furnished to do so, subject to the following conditions: |
19
|
|
|
* |
20
|
|
|
* The above copyright notice and this permission notice shall be included in all |
21
|
|
|
* copies or substantial portions of the Software. |
22
|
|
|
* |
23
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
24
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
25
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
26
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
27
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
28
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
29
|
|
|
* SOFTWARE. |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @file BrowserDetector.php |
34
|
|
|
* |
35
|
|
|
* The browser detector class |
36
|
|
|
* |
37
|
|
|
* @package Platine\UserAgent\Detector |
38
|
|
|
* @author Platine Developers Team |
39
|
|
|
* @copyright Copyright (c) 2020 |
40
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
41
|
|
|
* @link https://www.platine-php.com |
42
|
|
|
* @version 1.0.0 |
43
|
|
|
* @filesource |
44
|
|
|
*/ |
45
|
|
|
|
46
|
|
|
declare(strict_types=1); |
47
|
|
|
|
48
|
|
|
namespace Platine\UserAgent\Detector; |
49
|
|
|
|
50
|
|
|
use Platine\UserAgent\Entity\Browser; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @class BrowserDetector |
54
|
|
|
* @package Platine\UserAgent\Detector |
55
|
|
|
*/ |
56
|
|
|
class BrowserDetector extends AbstractDetector |
57
|
|
|
{ |
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function __construct() |
62
|
|
|
{ |
63
|
|
|
parent::__construct(); |
64
|
|
|
|
65
|
|
|
$this->entity = new Browser(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function maps(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
'oldsafari' => [ |
75
|
|
|
'version' => [ |
76
|
|
|
'1.0' => '/8', |
77
|
|
|
'1.2' => '/1', |
78
|
|
|
'1.3' => '/3', |
79
|
|
|
'2.0' => '/412', |
80
|
|
|
'2.0.2' => '/416', |
81
|
|
|
'2.0.3' => '/417', |
82
|
|
|
'2.0.4' => '/419', |
83
|
|
|
'?' => '/' |
84
|
|
|
] |
85
|
|
|
] |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function regex(): array |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
[ |
96
|
|
|
// Presto based |
97
|
|
|
'/(opera\smini)\/([\w\.-]+)/i', // Opera Mini |
98
|
|
|
'/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i', // Opera Mobi/Tablet |
99
|
|
|
'/(opera).+version\/([\w\.]+)/i', // Opera > 9.80 |
100
|
|
|
'/(opera)[\/\s]+([\w\.]+)/i' // Opera < 9.80 |
101
|
|
|
], [self::NAME, self::VERSION], [ |
102
|
|
|
'/(opios)[\/\s]+([\w\.]+)/i' // Opera mini on iphone >= 8.0 |
103
|
|
|
], [[self::NAME, 'Opera Mini'], self::VERSION], [ |
104
|
|
|
'/\s(opr)\/([\w\.]+)/i' // Opera Webkit |
105
|
|
|
], [[self::NAME, 'Opera'], self::VERSION], [ |
106
|
|
|
// Mixed |
107
|
|
|
'/(kindle)\/([\w\.]+)/i', // Kindle |
108
|
|
|
'/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i', |
109
|
|
|
// Lunascape/Maxthon/Netfront/Jasmine/Blazer |
110
|
|
|
|
111
|
|
|
// Trident based |
112
|
|
|
'/(avant\s|iemobile|slim|baidu)(?:browser)?[\/\s]?([\w\.]*)/i', |
113
|
|
|
// Avant/IEMobile/SlimBrowser/Baidu |
114
|
|
|
'/(?:ms|\()(ie)\s([\w\.]+)/i', // Internet Explorer |
115
|
|
|
|
116
|
|
|
// Webkit/KHTML based |
117
|
|
|
'/(rekonq)\/([\w\.]*)/i', // Rekonq |
118
|
|
|
'/(Instagram)\s([\w\.]+)/i', // Instagram inApp Browser |
119
|
|
|
'/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i' |
120
|
|
|
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon |
121
|
|
|
], [self::NAME, self::VERSION], [ |
122
|
|
|
'/(konqueror)\/([\w\.]+)/i' // Konqueror |
123
|
|
|
], [[self::NAME, 'Konqueror'], self::VERSION], [ |
124
|
|
|
'/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i' // IE11 |
125
|
|
|
], [[self::NAME, 'IE'], self::VERSION], [ |
126
|
|
|
'/(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i' // Microsoft Edge |
127
|
|
|
], [[self::NAME, 'Edge'], self::VERSION], [ |
128
|
|
|
'/(yabrowser)\/([\w\.]+)/i' // Yandex |
129
|
|
|
], [[self::NAME, 'Yandex'], self::VERSION], [ |
130
|
|
|
'/(puffin)\/([\w\.]+)/i' // Puffin |
131
|
|
|
], [[self::NAME, 'Puffin'], self::VERSION], [ |
132
|
|
|
|
133
|
|
|
'/(focus)\/([\w\.]+)/i' // Firefox Focus |
134
|
|
|
], [[self::NAME, 'Firefox Focus'], self::VERSION], [ |
135
|
|
|
|
136
|
|
|
'/(opt)\/([\w\.]+)/i' // Opera Touch |
137
|
|
|
], [[self::NAME, 'Opera Touch'], self::VERSION], [ |
138
|
|
|
|
139
|
|
|
'/((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i' // UCBrowser |
140
|
|
|
], [[self::NAME, 'UCBrowser'], self::VERSION], [ |
141
|
|
|
|
142
|
|
|
'/(comodo_dragon)\/([\w\.]+)/i' // Comodo Dragon |
143
|
|
|
], [[self::NAME, '/_/g', ' '], self::VERSION], [ |
144
|
|
|
|
145
|
|
|
'/(windowswechat qbcore)\/([\w\.]+)/i' // WeChat Desktop for Windows Built-in Browser |
146
|
|
|
], [[self::NAME, 'WeChat(Win) Desktop'], self::VERSION], [ |
147
|
|
|
|
148
|
|
|
'/(micromessenger)\/([\w\.]+)/i' // WeChat |
149
|
|
|
], [[self::NAME, 'WeChat'], self::VERSION], [ |
150
|
|
|
|
151
|
|
|
'/(brave)\/([\w\.]+)/i' // Brave browser |
152
|
|
|
], [[self::NAME, 'Brave'], self::VERSION], [ |
153
|
|
|
|
154
|
|
|
'/(qqbrowserlite)\/([\w\.]+)/i' // QQBrowserLite |
155
|
|
|
], [self::NAME, self::VERSION], [ |
156
|
|
|
|
157
|
|
|
'/(QQ)\/([\d\.]+)/i' // QQ, aka ShouQ |
158
|
|
|
], [self::NAME, self::VERSION], [ |
159
|
|
|
|
160
|
|
|
'/m?(qqbrowser)[\/\s]?([\w\.]+)/i' // QQBrowser |
161
|
|
|
], [self::NAME, self::VERSION], [ |
162
|
|
|
|
163
|
|
|
'/(BIDUBrowser)[\/\s]?([\w\.]+)/i' // Baidu Browser |
164
|
|
|
], [self::NAME, self::VERSION], [ |
165
|
|
|
|
166
|
|
|
'/(2345Explorer)[\/\s]?([\w\.]+)/i' // 2345 Browser |
167
|
|
|
], [self::NAME, self::VERSION], [ |
168
|
|
|
|
169
|
|
|
'/(MetaSr)[\/\s]?([\w\.]+)/i' // SouGouBrowser |
170
|
|
|
], [self::NAME], [ |
171
|
|
|
|
172
|
|
|
'/(LBBROWSER)/i' // LieBao Browser |
173
|
|
|
], [self::NAME], [ |
174
|
|
|
|
175
|
|
|
'/xiaomi\/miuibrowser\/([\w\.]+)/i' // MIUI Browser |
176
|
|
|
], [self::VERSION, [self::NAME, 'MIUI Browser']], [ |
177
|
|
|
|
178
|
|
|
'/;(fbav)\/([\w\.]+);/i' // Facebook App for iOS & Android |
179
|
|
|
], [[self::NAME, 'Facebook'], self::VERSION], [ |
180
|
|
|
|
181
|
|
|
'/safari\s(line)\/([\w\.]+)/i', // Line App for iOS |
182
|
|
|
'/android.+(line)\/([\w\.]+)\/iab/i' // Line App for Android |
183
|
|
|
], [self::NAME, self::VERSION], [ |
184
|
|
|
|
185
|
|
|
'/headlesschrome(?:\/([\w\.]+)|\s)/i' // Chrome Headless |
186
|
|
|
], [self::VERSION, [self::NAME, 'Chrome Headless']], [ |
187
|
|
|
|
188
|
|
|
'/\swv\).+(chrome)\/([\w\.]+)/i' // Chrome WebView |
189
|
|
|
], [[self::NAME, '/(.+)/', '$1 WebView'], self::VERSION], [ |
190
|
|
|
|
191
|
|
|
'/((?:oculus|samsung)browser)\/([\w\.]+)/i' |
192
|
|
|
], [[self::NAME, "/(.+(?:g|us))(.+)/", '$1 $2'], self::VERSION], [ // Oculus / Samsung Browser |
193
|
|
|
|
194
|
|
|
'/android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i' // Android Browser |
195
|
|
|
], [self::VERSION, [self::NAME, 'Android Browser']], [ |
196
|
|
|
|
197
|
|
|
'/(sailfishbrowser)\/([\w\.]+)/i' // Sailfish Browser |
198
|
|
|
], [[self::NAME, 'Sailfish Browser'], self::VERSION], [ |
199
|
|
|
|
200
|
|
|
'/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i' |
201
|
|
|
// Chrome/OmniWeb/Arora/Tizen/Nokia |
202
|
|
|
], [self::NAME, self::VERSION], [ |
203
|
|
|
|
204
|
|
|
'/(dolfin)\/([\w\.]+)/i' // Dolphin |
205
|
|
|
], [[self::NAME, 'Dolphin'], self::VERSION], [ |
206
|
|
|
|
207
|
|
|
'/((?:android.+)crmo|crios)\/([\w\.]+)/i' // Chrome for Android/iOS |
208
|
|
|
], [[self::NAME, 'Chrome'], self::VERSION], [ |
209
|
|
|
|
210
|
|
|
'/(coast)\/([\w\.]+)/i' // Opera Coast |
211
|
|
|
], [[self::NAME, 'Opera Coast'], self::VERSION], [ |
212
|
|
|
|
213
|
|
|
'/fxios\/([\w\.-]+)/i' // Firefox for iOS |
214
|
|
|
], [self::VERSION, [self::NAME, 'Firefox']], [ |
215
|
|
|
|
216
|
|
|
'/version\/([\w\.]+).+?mobile\/\w+\s(safari)/i' // Mobile Safari |
217
|
|
|
], [self::VERSION, [self::NAME, 'Mobile Safari']], [ |
218
|
|
|
|
219
|
|
|
'/version\/([\w\.]+).+?(mobile\s?safari|safari)/i' // Safari & Safari Mobile |
220
|
|
|
], [self::VERSION, self::NAME], [ |
221
|
|
|
|
222
|
|
|
'/webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i' // Google Search Appliance on iOS |
223
|
|
|
], [[self::NAME, 'GSA'], self::VERSION], [ |
224
|
|
|
|
225
|
|
|
'/webkit.+?(mobile\s?safari|safari)(\/[\w]+)/i' // Safari < 3.0 |
226
|
|
|
], [self::NAME, [self::VERSION, '__str', 'oldsafari.version']], [ |
227
|
|
|
|
228
|
|
|
'/(webkit|khtml)\/([\w\.]+)/i' |
229
|
|
|
], [self::NAME, self::VERSION], [ |
230
|
|
|
|
231
|
|
|
// Gecko based |
232
|
|
|
'/(navigator|netscape)\/([\w\.-]+)/i' // Netscape |
233
|
|
|
], [[self::NAME, 'Netscape'], self::VERSION], [ |
234
|
|
|
'/(swiftfox)/i', // Swiftfox |
235
|
|
|
'/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i', |
236
|
|
|
// IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror |
237
|
|
|
'/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i', |
238
|
|
|
|
239
|
|
|
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix |
240
|
|
|
'/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i', // Mozilla |
241
|
|
|
|
242
|
|
|
// Other |
243
|
|
|
'/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i', |
244
|
|
|
// Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir |
245
|
|
|
'/(links)\s\(([\w\.]+)/i', // Links |
246
|
|
|
'/(gobrowser)\/?([\w\.]*)/i', // GoBrowser |
247
|
|
|
'/(ice\s?browser)\/v?([\w\._]+)/i', // ICE Browser |
248
|
|
|
'/(mosaic)[\/\s]([\w\.]+)/i' // Mosaic |
249
|
|
|
], [self::NAME, self::VERSION], |
250
|
|
|
]; |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|