public function detect($userAgent = null, $advanced = false) { $userAgent = $userAgent ?: env('HTTP_USER_AGENT'); DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE); $detect = new DeviceDetector($userAgent); $detect->parse(); $return = []; if ($detect->isBot()) { $return['bot'] = $detect->getBot(); return $return; } //device wrapper $devicelist = ['desktop' => 'computer', 'smartphone' => 'phone', 'tablet' => 'tablet', 'feature phone' => 'phone']; $os = $detect->getOs(); $client = $detect->getClient(); $devicename = $detect->getDeviceName(); $devicetype = isset($devicelist[$devicename]) ? $devicelist[$devicename] : 'computer'; //legacy params $return['device'] = $devicename; $return['type'] = $devicetype; $return['brand'] = $detect->getBrandName(); $return['os'] = $os['name']; $return['os_version'] = $os['version']; $return['os_code'] = $os['short_name']; $return['browser'] = $client['name']; $return['browser_version'] = $client['version']; $return['browser_code'] = $client['short_name']; $return['browser_type'] = $client['type']; $return['browser_engine'] = $client['engine']; if (!$advanced) { return array_map('trim', $return); } //advanced params $osFamily = OperatingSystem::getOsFamily($os['short_name']); $return['os_family'] = $osFamily !== false ? $osFamily : 'Unknown'; $return['model'] = $detect->getModel(); $browserFamily = Browser::getBrowserFamily($client['short_name']); $return['browser_family'] = $browserFamily !== false ? $browserFamily : 'Unknown'; $touch = $detect->isTouchEnabled(); $return['touch'] = $touch[0]; unset($os, $client, $osFamily, $browserFamily, $touch); return array_map('trim', $return); }
/** * * @param Model\UserAgent $device * @param DeviceDetector $dd */ private function hydrateDevice(Model\Device $device, DeviceDetector $dd) { $device->setModel($this->getRealResult($dd->getModel())); $device->setBrand($this->getRealResult($dd->getBrandName())); $device->setType($this->getRealResult($dd->getDeviceName())); if ($dd->isMobile() === true) { $device->setIsMobile(true); } if ($dd->isTouchEnabled() === true) { $device->setIsTouch(true); } }