Skip to content

Commit a446934

Browse files
authored
Merge pull request #80 from cbschuld/curl_and_wget
adds curl and wget support
2 parents bc3e602 + aa3e6c4 commit a446934

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
@@ -75,6 +75,9 @@ class Browser
7575
const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
7676
const BROWSER_ANDROID = 'Android'; // http://www.android.com/
7777
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
78+
const BROWSER_CURL = 'cURL'; // https://en.wikipedia.org/wiki/CURL
79+
const BROWSER_WGET = 'Wget'; // https://en.wikipedia.org/wiki/Wget
80+
7881

7982
const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
8083
const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots
@@ -480,6 +483,8 @@ protected function checkBrowsers()
480483
$this->checkBrowserIceCat() ||
481484
$this->checkBrowserIceweasel() ||
482485
$this->checkBrowserW3CValidator() ||
486+
$this->checkBrowserCurl() ||
487+
$this->checkBrowserWget() ||
483488
$this->checkBrowserPlayStation() ||
484489
$this->checkBrowserIframely() ||
485490
$this->checkBrowserCocoa() ||
@@ -1706,6 +1711,39 @@ protected function checkBrowserPlayStation()
17061711
return false;
17071712
}
17081713

1714+
/**
1715+
* Determine if the browser is Wget or not (last updated 1.7)
1716+
* @return boolean True if the browser is Wget otherwise false
1717+
*/
1718+
protected function checkBrowserWget ()
1719+
{
1720+
if (preg_match("!^Wget/([^ ]+)!i", $this->_agent, $aresult))
1721+
{
1722+
$this->setVersion($aresult[1]);
1723+
$this->setBrowser(self::BROWSER_WGET);
1724+
return true;
1725+
}
1726+
return false;
1727+
}
1728+
/**
1729+
* Determine if the browser is cURL or not (last updated 1.7)
1730+
* @return boolean True if the browser is cURL otherwise false
1731+
*/
1732+
protected function checkBrowserCurl ()
1733+
{
1734+
if (strpos($this->_agent, 'curl') === 0)
1735+
{
1736+
$aresult = explode('/', stristr($this->_agent, 'curl'));
1737+
if (isset($aresult[1])) {
1738+
$aversion = explode(' ', $aresult[1]);
1739+
$this->setVersion($aversion[0]);
1740+
$this->setBrowser(self::BROWSER_CURL);
1741+
return true;
1742+
}
1743+
}
1744+
return false;
1745+
}
1746+
17091747
/**
17101748
* Determine the user's platform (last updated 2.0)
17111749
*/

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)