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 OsDetector.php |
34
|
|
|
* |
35
|
|
|
* The Operating System 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\Os; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @class OsDetector |
54
|
|
|
* @package Platine\UserAgent\Detector |
55
|
|
|
*/ |
56
|
|
|
class OsDetector extends AbstractDetector |
57
|
|
|
{ |
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function __construct() |
62
|
|
|
{ |
63
|
|
|
parent::__construct(); |
64
|
|
|
|
65
|
|
|
$this->entity = new Os(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function maps(): array |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
'windows' => [ |
76
|
|
|
'versions' => [ |
77
|
|
|
'ME' => '4.90', |
78
|
|
|
'NT 3.11' => 'NT3.51', |
79
|
|
|
'NT 4.0' => 'NT4.0', |
80
|
|
|
'2000' => 'NT 5.0', |
81
|
|
|
'XP' => ['NT 5.1', 'NT 5.2'], |
82
|
|
|
'Vista' => 'NT 6.0', |
83
|
|
|
'7' => 'NT 6.1', |
84
|
|
|
'8' => 'NT 6.2', |
85
|
|
|
'8.1' => 'NT 6.3', |
86
|
|
|
'10' => ['NT 6.4', 'NT 10.0'], |
87
|
|
|
'RT' => 'ARM' |
88
|
|
|
] |
89
|
|
|
] |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function regex(): array |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
[ |
100
|
|
|
// Windows based |
101
|
|
|
'/microsoft\s(windows)\s(vista|xp)/i' // Windows (iTunes) |
102
|
|
|
], [self::NAME, self::VERSION], [ |
103
|
|
|
'/(windows)\snt\s6\.2;\s(arm)/i', // Windows RT |
104
|
|
|
'/(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i', // Windows Phone |
105
|
|
|
'/(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i' |
106
|
|
|
], [self::NAME, [self::VERSION, '__str', 'windows.versions']], [ |
107
|
|
|
'/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i' |
108
|
|
|
], [[self::NAME, 'Windows'], [self::VERSION, '__str', 'windows.version']], [ |
109
|
|
|
|
110
|
|
|
// Mobile/Embedded OS |
111
|
|
|
'/\((bb)(10);/i' // BlackBerry 10 |
112
|
|
|
], [[self::NAME, 'BlackBerry'], self::VERSION], [ |
113
|
|
|
'/(blackberry)\w*\/?([\w\.]*)/i', // Blackberry |
114
|
|
|
'/(tizen)[\/\s]([\w\.]+)/i', // Tizen |
115
|
|
|
'/(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i' |
116
|
|
|
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS |
117
|
|
|
], [self::NAME, self::VERSION], [ |
118
|
|
|
'/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i' // Symbian |
119
|
|
|
], [[self::NAME, 'Symbian'], self::VERSION], [ |
120
|
|
|
'/\((series40);/i' // Series 40 |
121
|
|
|
], [self::NAME], [ |
122
|
|
|
'/mozilla.+\(mobile;.+gecko.+firefox/i' // Firefox OS |
123
|
|
|
], [[self::NAME, 'Firefox OS'], self::VERSION], [ |
124
|
|
|
|
125
|
|
|
// Console |
126
|
|
|
'/(nintendo|playstation)\s([wids34portablevu]+)/i', // Nintendo/Playstation |
127
|
|
|
|
128
|
|
|
// GNU/Linux based |
129
|
|
|
'/(mint)[\/\s\(]?(\w*)/i', // Mint |
130
|
|
|
'/(mageia|vectorlinux)[;\s]/i', // Mageia/VectorLinux |
131
|
|
|
'/(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i', |
132
|
|
|
// Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware |
133
|
|
|
// Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus |
134
|
|
|
'/(hurd|linux)\s?([\w\.]*)/i', // Hurd/Linux |
135
|
|
|
'/(gnu)\s?([\w\.]*)/i' // GNU |
136
|
|
|
], [self::NAME, self::VERSION], [ |
137
|
|
|
|
138
|
|
|
'/(cros)\s[\w]+\s([\w\.]+\w)/i' // Chromium OS |
139
|
|
|
], [[self::NAME, 'Chromium OS'], self::VERSION], [ |
140
|
|
|
|
141
|
|
|
// Solaris |
142
|
|
|
'/(sunos)\s?([\w\.\d]*)/i' // Solaris |
143
|
|
|
], [[self::NAME, 'Solaris'], self::VERSION], [ |
144
|
|
|
|
145
|
|
|
// BSD based |
146
|
|
|
'/\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i' // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly |
147
|
|
|
], [self::NAME, self::VERSION], [ |
148
|
|
|
|
149
|
|
|
'/(haiku)\s(\w+)/i' // Haiku |
150
|
|
|
], [self::NAME, self::VERSION], [ |
151
|
|
|
|
152
|
|
|
'/cfnetwork\/.+darwin/i', |
153
|
|
|
'/ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i' // iOS |
154
|
|
|
], [[self::VERSION, '/_/', '.'], [self::NAME, 'iOS']], [ |
155
|
|
|
|
156
|
|
|
'/(mac\sos\sx)\s?([\w\s\.]*)/i', |
157
|
|
|
'/(macintosh|mac(?=_powerpc)\s)/i' // Mac OS |
158
|
|
|
], [[self::NAME, 'Mac OS'], [self::VERSION, '/_/', '.']], [ |
159
|
|
|
|
160
|
|
|
// Other |
161
|
|
|
'/((?:open)?solaris)[\/\s-]?([\w\.]*)/i', // Solaris |
162
|
|
|
'/(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i', // AIX |
163
|
|
|
'/(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i', |
164
|
|
|
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia |
165
|
|
|
'/(unix)\s?([\w\.]*)/i' // UNIX |
166
|
|
|
], [self::NAME, self::VERSION] |
167
|
|
|
]; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|