Skip to content

Commit 1870c94

Browse files
authored
Merge pull request #85 from cbschuld/ucbrowser
added UCBrowser
2 parents 100b312 + bec87c4 commit 1870c94

File tree

3 files changed

+566
-1
lines changed

3 files changed

+566
-1
lines changed

lib/Browser.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Browser
7878
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
7979
const BROWSER_CURL = 'cURL'; // https://en.wikipedia.org/wiki/CURL
8080
const BROWSER_WGET = 'Wget'; // https://en.wikipedia.org/wiki/Wget
81+
const BROWSER_UCBROWSER = 'UCBrowser'; // https://www.ucweb.com/
8182

8283

8384
const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
@@ -425,6 +426,7 @@ protected function checkBrowsers()
425426
// before Firefox and Chrome
426427
$this->checkBrowserWebTv() ||
427428
$this->checkBrowserBrave() ||
429+
$this->checkBrowserUCBrowser() ||
428430
$this->checkBrowserEdge() ||
429431
$this->checkBrowserInternetExplorer() ||
430432
$this->checkBrowserOpera() ||
@@ -1304,7 +1306,28 @@ protected function checkBrowserPalemoon()
13041306
}
13051307

13061308
/**
1307-
* Determine if the browser is Firefox or not (last updated 1.7)
1309+
* Determine if the browser is UCBrowser or not
1310+
* @return boolean True if the browser is UCBrowser otherwise false
1311+
*/
1312+
protected function checkBrowserUCBrowser()
1313+
{
1314+
if (preg_match('/UC ?Browser\/?([\d\.]+)/', $this->_agent, $matches )) {
1315+
if(isset($matches[1])) {
1316+
$this->setVersion($matches[1]);
1317+
}
1318+
if (stripos($this->_agent, 'Mobile') !== false) {
1319+
$this->setMobile(true);
1320+
} else {
1321+
$this->setTablet(true);
1322+
}
1323+
$this->setBrowser(self::BROWSER_UCBROWSER);
1324+
return true;
1325+
}
1326+
return false;
1327+
}
1328+
1329+
/**
1330+
* Determine if the browser is Firefox or not
13081331
* @return boolean True if the browser is Firefox otherwise false
13091332
*/
13101333
protected function checkBrowserFirefox()

tests/UCBrowserTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
require_once dirname(__FILE__)."/TabDelimitedFileIterator.php";
7+
8+
final class UCBrowserTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider userAgentUCBrowserProvider
12+
* @param $userAgent string Browser's User Agent
13+
* @param $type string Type of the Browser
14+
* @param $browser string Name of the Browser
15+
* @param $version string Version of the Browser
16+
* @param $osType string Type of operating system associated with the Browser
17+
* @param $osName string Name of the operating system associated with the Browser, typically has the version number
18+
* @param $osVersionName string Version of the Operating System (name)
19+
* @param $osVersionNumber string Version of the Operating System (number)
20+
*/
21+
public function testUCBrowserUserAgent($userAgent,$type,$browser,$version,$osType,$osName,$osVersionName,$osVersionNumber)
22+
{
23+
$b = new Browser($userAgent);
24+
25+
$this->assertSame($browser, $b->getBrowser());
26+
$this->assertSame($version, $b->getVersion());
27+
}
28+
29+
public function userAgentUCBrowserProvider()
30+
{
31+
return new TabDelimitedFileIterator(dirname(__FILE__).'/lists/ucbrowser.txt');
32+
}
33+
}

0 commit comments

Comments
 (0)