From e1bee473663bb82e5ff58a3a2c0bf81c8671de5a Mon Sep 17 00:00:00 2001 From: Gabriel Bull Date: Wed, 28 Dec 2016 11:31:30 -0500 Subject: [PATCH] Added wkhtmltopdf detection --- CHANGELOG.md | 4 ++++ src/Browser.php | 1 + src/BrowserDetector.php | 16 ++++++++++++++++ .../Tests/_files/UserAgentStrings.xml | 11 +++++++++++ 4 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7aecf..784c76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 6.1.2 (released 2016-12-13) + +- Added wkhtmltopdf detection + ## 6.1.1 (released 2016-12-13) - Added Samsung Browser detection diff --git a/src/Browser.php b/src/Browser.php index e40e837..2e34aca 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -25,6 +25,7 @@ class Browser const MOZILLA = 'Mozilla'; const AMAYA = 'Amaya'; const LYNX = 'Lynx'; + const WKHTMLTOPDF = 'wkhtmltopdf'; const SAFARI = 'Safari'; const SAMSUNG_BROWSER = 'SamsungBrowser'; const CHROME = 'Chrome'; diff --git a/src/BrowserDetector.php b/src/BrowserDetector.php index df07c15..5156188 100644 --- a/src/BrowserDetector.php +++ b/src/BrowserDetector.php @@ -53,6 +53,8 @@ class BrowserDetector implements DetectorInterface 'Gsa', // common bots 'Robot', + // wkhtmltopdf before Safari + 'Wkhtmltopdf', // WebKit base check (post mobile and others) 'Safari', // everyone else @@ -899,6 +901,20 @@ public static function checkBrowserAmaya() return false; } + /** + * Determine if the browser is Safari. + * + * @return bool + */ + public static function checkBrowserWkhtmltopdf() + { + if (stripos(self::$userAgentString, 'wkhtmltopdf') !== false) { + self::$browser->setName(Browser::WKHTMLTOPDF); + return true; + } + + return false; + } /** * Determine if the browser is Safari. * diff --git a/tests/BrowserDetector/Tests/_files/UserAgentStrings.xml b/tests/BrowserDetector/Tests/_files/UserAgentStrings.xml index 0d91a2f..d6628ec 100644 --- a/tests/BrowserDetector/Tests/_files/UserAgentStrings.xml +++ b/tests/BrowserDetector/Tests/_files/UserAgentStrings.xml @@ -263,5 +263,16 @@ Mozilla/5.0 (Linux; Android 5.1.1; SAMSUNG SM-G360T1 Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/3.3 Chrome/38.0.2125.102 Mobile Safari/537.36 + + wkhtmltopdf + unknown + Linux + unknown + unknown + unknown + + Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) wkhtmltopdf-amd64 Safari/534.34 + +