From aa3e6c45b6a17096aedf3b8e9a076273ad543fff Mon Sep 17 00:00:00 2001 From: Chris Schuld Date: Mon, 8 Jul 2019 16:02:26 -0700 Subject: [PATCH] adds curl and wget support - original work by https://github.com/willemstuursma - fixes #79 --- lib/Browser.php | 38 ++++++++++++++++++++++++++++++++++++++ tests/CurlWgetTest.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/CurlWgetTest.php diff --git a/lib/Browser.php b/lib/Browser.php index 5dc957f..f24b1d4 100644 --- a/lib/Browser.php +++ b/lib/Browser.php @@ -74,6 +74,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 @@ -478,6 +481,8 @@ protected function checkBrowsers() $this->checkBrowserIceCat() || $this->checkBrowserIceweasel() || $this->checkBrowserW3CValidator() || + $this->checkBrowserCurl() || + $this->checkBrowserWget() || $this->checkBrowserPlayStation() || $this->checkBrowserIframely() || $this->checkBrowserCocoa() || @@ -1680,6 +1685,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) */ diff --git a/tests/CurlWgetTest.php b/tests/CurlWgetTest.php new file mode 100644 index 0000000..8cee0c1 --- /dev/null +++ b/tests/CurlWgetTest.php @@ -0,0 +1,32 @@ +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'), + ); + } +} \ No newline at end of file