Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some popular browsers, devices and robots. #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class Agent extends Mobile_Detect
* @var array
*/
protected static $additionalDevices = [
'HUAWEI' => 'HUAWEI',
'HONOR' => 'HONOR',
'vivo' => 'vivo [\w+]',
'OPPO' => 'OPPO [\w+]',
'Redmi' => 'Redmi [\w+]',
'MI' => 'MI [\w+]',
'Samsung' => 'SM-?[\w+]',
'Macintosh' => 'Macintosh',
];

Expand Down Expand Up @@ -41,6 +48,11 @@ class Agent extends Mobile_Detect
* @var array
*/
protected static $additionalBrowsers = [
'MicroMessenger' => 'MicroMessenger',
'QQ' => 'QQ/[.0-9]+',
'Weibo' => 'Weibo',
'Alipay' => 'AliApp\(AP/[.0-9]+\)',
'Taobao' => 'AliApp\(TB/[.0-9]+\)',
'Opera Mini' => 'Opera Mini',
'Opera' => 'Opera|OPR',
'Edge' => 'Edge',
Expand Down Expand Up @@ -76,6 +88,11 @@ class Agent extends Mobile_Detect
'IE' => ['IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'rv:[VER]'],
'Edge' => 'Edge/[VER]',
'Vivaldi' => 'Vivaldi/[VER]',
'MicroMessenger' => 'MicroMessenger/[VER]',
'QQ' => 'QQ/[VER]',
'Weibo' => 'weibo__[VER]__(iphone|android)__[\w+]',
'Alipay' => 'AliApp\(AP/[VER]\)',
'Taobao' => 'AliApp\(TB/[VER]\)',
];

/**
Expand Down Expand Up @@ -170,7 +187,7 @@ public function languages($acceptLanguage = null)
* Match a detection rule and return the matched key.
*
* @param array $rules
* @param null $userAgent
* @param null $userAgent
* @return string
*/
protected function findDetectionRulesAgainstUA(array $rules, $userAgent = null)
Expand Down Expand Up @@ -248,8 +265,8 @@ public function device($userAgent = null)
/**
* Check if the device is a desktop computer.
*
* @param string $userAgent deprecated
* @param array $httpHeaders deprecated
* @param string $userAgent deprecated
* @param array $httpHeaders deprecated
* @return bool
*/
public function isDesktop($userAgent = null, $httpHeaders = null)
Expand All @@ -260,8 +277,8 @@ public function isDesktop($userAgent = null, $httpHeaders = null)
/**
* Check if the device is a mobile phone.
*
* @param string $userAgent deprecated
* @param array $httpHeaders deprecated
* @param string $userAgent deprecated
* @param array $httpHeaders deprecated
* @return bool
*/
public function isPhone($userAgent = null, $httpHeaders = null)
Expand Down Expand Up @@ -331,7 +348,7 @@ protected function mergeRules()
if (is_array($merged[$key])) {
$merged[$key][] = $value;
} else {
$merged[$key] .= '|'.$value;
$merged[$key] .= '|' . $value;
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AgentTest extends TestCase
'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' => 'Windows',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2' => 'OS X',
'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3' => 'iOS',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79 MicroMessenger/6.7.1 NetType/WIFI Language/zh_CN' => 'iOS',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0' => 'Ubuntu',
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+' => 'BlackBerryOS',
'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'AndroidOS',
Expand All @@ -29,6 +30,13 @@ class AgentTest extends TestCase
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Vivaldi/1.2.490.43' => 'Vivaldi',
'Mozilla/5.0 (Linux; U; Android 4.0.4; en-US; LT28h Build/6.1.E.3.7) AppleWebKit/534.31 (KHTML, like Gecko) UCBrowser/9.2.2.323 U3/0.8.0 Mobile Safari/534.31' => 'UCBrowser',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063' => 'Edge',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79 MicroMessenger/6.7.1 NetType/WIFI Language/zh_CN' => 'MicroMessenger',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5327f QQ/7.6.3.466 V1_IPH_SQ_7.6.3_1_APP_A Pixel/640 Core/UIWebView Device/Apple(Unknown iOS device) NetType/WIFI QBWebViewType/1' => 'QQ',
'Mozilla/5.0 (Linux; Android 8.1.0; MI 6X Build/OPM1.171019.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36 MicroMessenger/6.7.1321(0x26070030) NetType/WIFI Language/zh_CN' => 'MicroMessenger',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79 Weibo (iPhone8,2__weibo__7.10.1__iphone__os11.4)' => 'Weibo',
'Mozilla/5.0 (Linux; Android 7.1.1; vivo X20A Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36 Weibo (vivo-vivo X20A__weibo__8.7.2__android__android7.1.1)' => 'Weibo',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5327f NebulaSDK/1.8.100112 Nebula PSDType(1) AlipayDefined(nt:WIFI,ws:320|504|2.0) AliApp(AP/10.1.30.300) AlipayClient/10.1.30.300 Language/zh-Hans' => 'Alipay',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5327f AliApp(TB/7.10.0) WindVane/8.4.2 UT4Aplus/1.0.0 640x1136' => 'Taobao',
];

private $robots = [
Expand All @@ -37,6 +45,7 @@ class AgentTest extends TestCase
'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)' => 'Bingbot',
'Twitterbot/1.0' => 'Twitterbot',
'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)' => 'Yandex',
'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)' => 'Baiduspider',
];

private $mobileDevices = [
Expand All @@ -46,6 +55,13 @@ class AgentTest extends TestCase
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+' => 'BlackBerry',
'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'Nexus',
'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; ASUS Transformer Pad TF300T Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30' => 'AsusTablet',
'Mozilla/5.0 (Linux; Android 8.1; MI 8 Build/OPM1.171019.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044103 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060736) NetType/4G Language/zh_CN' => 'MI',
'Mozilla/5.0 (Linux; Android 6.0; Redmi Note 4X Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 Mobile Safari/537.36 Weibo (Xiaomi-Redmi Note 4X__weibo__8.5.2__android__android6.0)' => 'Redmi',
'Mozilla/5.0 (Linux; Android 8.0; MHA-AL00 Build/HUAWEIMHA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044033 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060737) NetType/WIFI Language/zh_CN' => 'HUAWEI',
'Mozilla/5.0 (Linux; Android 8.0; LND-AL40 Build/HONORLND-AL40; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044033 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060737) NetType/4G Language/zh_CN' => 'HONOR',
'Mozilla/5.0 (Linux; Android 7.1.1; vivo X20 Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044103 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060737) NetType/WIFI Language/zh_CN' => 'vivo',
'Mozilla/5.0 (Linux; Android 7.1.1; OPPO R11 Plus Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36aweme_210 JsSdk/1.0 NetType/WIFI Channel/oppo' => 'OPPO',
'Mozilla/5.0 (Linux; Android 7.0; SM-C5010 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044034 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060737) NetType/WIFI Language/zh_CN' => 'Samsung',
];

private $desktopDevices = [
Expand All @@ -64,6 +80,11 @@ class AgentTest extends TestCase
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51' => '11.51',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12' => '12',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Vivaldi/1.2.490.43' => '1.2.490.43',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79 MicroMessenger/6.7.1 NetType/WIFI Language/zh_CN' => '6.7.1',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5327f QQ/7.6.3.466 V1_IPH_SQ_7.6.3_1_APP_A Pixel/640 Core/UIWebView Device/Apple(Unknown iOS device) NetType/WIFI QBWebViewType/1' => '7.6.3.466',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79 Weibo (iPhone8,2__weibo__7.10.1__iphone__os11.4)' => '7.10.1',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5327f NebulaSDK/1.8.100112 Nebula PSDType(1) AlipayDefined(nt:WIFI,ws:320|504|2.0) AliApp(AP/10.1.30.300) AlipayClient/10.1.30.300 Language/zh-Hans' => '10.1.30.300',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5327f AliApp(TB/7.10.0) WindVane/8.4.2 UT4Aplus/1.0.0 640x1136' => '7.10.0',
];

private $operatingSystemVersions = [
Expand Down