From 6634a151ab0b4a9b7d09406e6583018ed25775ce Mon Sep 17 00:00:00 2001 From: Niels Leenheer Date: Sat, 7 Nov 2015 00:00:33 +0100 Subject: [PATCH 1/2] Don't re-use the parser object --- src/Provider/WhichBrowser.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Provider/WhichBrowser.php b/src/Provider/WhichBrowser.php index 0ecc21d..af4e596 100644 --- a/src/Provider/WhichBrowser.php +++ b/src/Provider/WhichBrowser.php @@ -17,24 +17,9 @@ public function getName() * * @return \WhichBrowser */ - private function getParser() - { - if ($this->parser !== null) { - return $this->parser; - } - - $parser = new \WhichBrowser([]); - - $this->parser = $parser; - - return $this->parser; - } - public function parse($userAgent) { - $parser = $this->getParser(); - $parser->analyseUserAgent($userAgent); - + $parser = new \WhichBrowser(array('headers' => array('User-Agent' => $userAgent))); $raw = $parser->toArray(); /* From ceb918ad4615eef511e1898db103e6474a615c78 Mon Sep 17 00:00:00 2001 From: Niels Leenheer Date: Sat, 7 Nov 2015 00:01:04 +0100 Subject: [PATCH 2/2] Use more data we get from the parser for comparisons --- src/Provider/WhichBrowser.php | 75 ++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/src/Provider/WhichBrowser.php b/src/Provider/WhichBrowser.php index af4e596..5233779 100644 --- a/src/Provider/WhichBrowser.php +++ b/src/Provider/WhichBrowser.php @@ -1,7 +1,6 @@ $osVersion, 'platform' => null ], + + 'device' => [ + 'brand' => $deviceManufacturer, + 'model' => $deviceModel, + 'type' => $raw['device']['type'], + + 'isMobile' => $raw['device']['type'] == 'mobile', + ], + + 'bot' => [ + 'isBot' => false, + + 'name' => null, + 'type' => null + ], 'raw' => $raw ]);