Skip to content

Commit aa3e6c4

Browse files
committed
adds curl and wget support - original work by https://github.com/willemstuursma - fixes #79
1 parent f48bdc9 commit aa3e6c4

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

lib/Browser.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class Browser
7474
const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
7575
const BROWSER_ANDROID = 'Android'; // http://www.android.com/
7676
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
77+
const BROWSER_CURL = 'cURL'; // https://en.wikipedia.org/wiki/CURL
78+
const BROWSER_WGET = 'Wget'; // https://en.wikipedia.org/wiki/Wget
79+
7780

7881
const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
7982
const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots
@@ -478,6 +481,8 @@ protected function checkBrowsers()
478481
$this->checkBrowserIceCat() ||
479482
$this->checkBrowserIceweasel() ||
480483
$this->checkBrowserW3CValidator() ||
484+
$this->checkBrowserCurl() ||
485+
$this->checkBrowserWget() ||
481486
$this->checkBrowserPlayStation() ||
482487
$this->checkBrowserIframely() ||
483488
$this->checkBrowserCocoa() ||
@@ -1680,6 +1685,39 @@ protected function checkBrowserPlayStation()
16801685
return false;
16811686
}
16821687

1688+
/**
1689+
* Determine if the browser is Wget or not (last updated 1.7)
1690+
* @return boolean True if the browser is Wget otherwise false
1691+
*/
1692+
protected function checkBrowserWget ()
1693+
{
1694+
if (preg_match("!^Wget/([^ ]+)!i", $this->_agent, $aresult))
1695+
{
1696+
$this->setVersion($aresult[1]);
1697+
$this->setBrowser(self::BROWSER_WGET);
1698+
return true;
1699+
}
1700+
return false;
1701+
}
1702+
/**
1703+
* Determine if the browser is cURL or not (last updated 1.7)
1704+
* @return boolean True if the browser is cURL otherwise false
1705+
*/
1706+
protected function checkBrowserCurl ()
1707+
{
1708+
if (strpos($this->_agent, 'curl') === 0)
1709+
{
1710+
$aresult = explode('/', stristr($this->_agent, 'curl'));
1711+
if (isset($aresult[1])) {
1712+
$aversion = explode(' ', $aresult[1]);
1713+
$this->setVersion($aversion[0]);
1714+
$this->setBrowser(self::BROWSER_CURL);
1715+
return true;
1716+
}
1717+
}
1718+
return false;
1719+
}
1720+
16831721
/**
16841722
* Determine the user's platform (last updated 2.0)
16851723
*/

tests/CurlWgetTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
// originally created by - @willemstuursma - https://github.com/willemstuursma
5+
6+
use PHPUnit\Framework\TestCase;
7+
8+
require_once dirname(__FILE__)."/TabDelimitedFileIterator.php";
9+
10+
final class CurlWgetTest extends TestCase
11+
{
12+
/**
13+
* @param $user_agent
14+
* @param $expected_browser
15+
* @param $expected_version
16+
*
17+
* @dataProvider dpUserAgents
18+
*/
19+
public function testBrowserDetectedCorrectly ($user_agent, $expected_browser, $expected_version)
20+
{
21+
$browser = new Browser($user_agent);
22+
$this->assertEquals($expected_browser, $browser->getBrowser());
23+
$this->assertEquals($expected_version, $browser->getVersion());
24+
}
25+
public function dpUserAgents ()
26+
{
27+
return array(
28+
array("curl/7.37.1", Browser::BROWSER_CURL, '7.37.1'),
29+
array("Wget/1.16 (darwin14.0.0)", Browser::BROWSER_WGET, '1.16'),
30+
);
31+
}
32+
}

0 commit comments

Comments
 (0)