Skip to content

Commit

Permalink
Merge pull request #80 from cbschuld/curl_and_wget
Browse files Browse the repository at this point in the history
adds curl and wget support
  • Loading branch information
cbschuld authored Jul 8, 2019
2 parents bc3e602 + aa3e6c4 commit a446934
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Browser
const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
const BROWSER_ANDROID = 'Android'; // http://www.android.com/
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
const BROWSER_CURL = 'cURL'; // https://en.wikipedia.org/wiki/CURL
const BROWSER_WGET = 'Wget'; // https://en.wikipedia.org/wiki/Wget


const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots
Expand Down Expand Up @@ -480,6 +483,8 @@ protected function checkBrowsers()
$this->checkBrowserIceCat() ||
$this->checkBrowserIceweasel() ||
$this->checkBrowserW3CValidator() ||
$this->checkBrowserCurl() ||
$this->checkBrowserWget() ||
$this->checkBrowserPlayStation() ||
$this->checkBrowserIframely() ||
$this->checkBrowserCocoa() ||
Expand Down Expand Up @@ -1706,6 +1711,39 @@ protected function checkBrowserPlayStation()
return false;
}

/**
* Determine if the browser is Wget or not (last updated 1.7)
* @return boolean True if the browser is Wget otherwise false
*/
protected function checkBrowserWget ()
{
if (preg_match("!^Wget/([^ ]+)!i", $this->_agent, $aresult))
{
$this->setVersion($aresult[1]);
$this->setBrowser(self::BROWSER_WGET);
return true;
}
return false;
}
/**
* Determine if the browser is cURL or not (last updated 1.7)
* @return boolean True if the browser is cURL otherwise false
*/
protected function checkBrowserCurl ()
{
if (strpos($this->_agent, 'curl') === 0)
{
$aresult = explode('/', stristr($this->_agent, 'curl'));
if (isset($aresult[1])) {
$aversion = explode(' ', $aresult[1]);
$this->setVersion($aversion[0]);
$this->setBrowser(self::BROWSER_CURL);
return true;
}
}
return false;
}

/**
* Determine the user's platform (last updated 2.0)
*/
Expand Down
32 changes: 32 additions & 0 deletions tests/CurlWgetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

// originally created by - @willemstuursma - https://github.com/willemstuursma

use PHPUnit\Framework\TestCase;

require_once dirname(__FILE__)."/TabDelimitedFileIterator.php";

final class CurlWgetTest extends TestCase
{
/**
* @param $user_agent
* @param $expected_browser
* @param $expected_version
*
* @dataProvider dpUserAgents
*/
public function testBrowserDetectedCorrectly ($user_agent, $expected_browser, $expected_version)
{
$browser = new Browser($user_agent);
$this->assertEquals($expected_browser, $browser->getBrowser());
$this->assertEquals($expected_version, $browser->getVersion());
}
public function dpUserAgents ()
{
return array(
array("curl/7.37.1", Browser::BROWSER_CURL, '7.37.1'),
array("Wget/1.16 (darwin14.0.0)", Browser::BROWSER_WGET, '1.16'),
);
}
}

0 comments on commit a446934

Please sign in to comment.