diff --git a/src/Provider/WhichBrowser.php b/src/Provider/WhichBrowser.php index 0ecc21d..5233779 100644 --- a/src/Provider/WhichBrowser.php +++ b/src/Provider/WhichBrowser.php @@ -1,7 +1,6 @@ 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(); /* @@ -50,21 +34,70 @@ public function parse($userAgent) if (isset($raw['browser']['name'])) { $browserFamily = $raw['browser']['name']; } - + if (isset($raw['browser']['alias'])) { + $browserFamily = $raw['browser']['alias']; + } + $browserVersion = null; if (isset($raw['browser']['version'])) { - $browserVersion = $raw['browser']['version']; + if(is_array($raw['browser']['version'])) { + if(isset($raw['browser']['version']['alias'])){ + $browserVersion = $raw['browser']['version']['alias']; + } else { + $browserVersion = $raw['browser']['version']['value']; + } + + if(isset($raw['browser']['version']['nickname'])){ + $osVersion .= ' ' . $raw['browser']['version']['nickname']; + } + } + else { + $browserVersion = $raw['browser']['version']; + } } $osFamily = null; if (isset($raw['os']['name'])) { $osFamily = $raw['os']['name']; } + if (isset($raw['os']['alias'])) { + $osFamily = $raw['os']['alias']; + } $osVersion = null; - // if(isset($raw['os']['version'])){ - // $osVersion = $raw['os']['version']; - // } + if(isset($raw['os']['version'])){ + if(is_array($raw['os']['version'])) { + if(isset($raw['os']['version']['alias'])){ + $osVersion = $raw['os']['version']['alias']; + } else { + $osVersion = $raw['os']['version']['value']; + } + + if(isset($raw['os']['version']['nickname'])){ + $osVersion .= ' ' . $raw['os']['version']['nickname']; + } + } + else { + $osVersion = $raw['os']['version']; + } + } + + $deviceManufacturer = null; + if (isset($raw['device']['manufacturer'])) { + $deviceManufacturer = $raw['device']['manufacturer']; + } + + $deviceModel = null; + if (isset($raw['device']['model'])) { + $deviceModel = $raw['device']['model']; + + if (isset($raw['device']['series'])) { + $deviceModel .= ' ' . $raw['device']['series']; + } + } + elseif (isset($raw['device']['series'])) { + $deviceModel = $raw['device']['series']; + } /* * Bot found @@ -98,6 +131,21 @@ public function parse($userAgent) 'version' => $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 ]);