public function testGetType() { $main = new Main(); $main->device->reset(['type' => Constants\DeviceType::GAMING]); $this->assertEquals('gaming', $main->getType()); $main->device->reset(['type' => Constants\DeviceType::GAMING, 'subtype' => Constants\DeviceSubType::CONSOLE]); $this->assertEquals('gaming:console', $main->getType()); $main->device->reset(['type' => Constants\DeviceType::GAMING, 'subtype' => Constants\DeviceSubType::PORTABLE]); $this->assertEquals('gaming:portable', $main->getType()); $main->device->reset(['type' => Constants\DeviceType::MOBILE]); $this->assertEquals('mobile', $main->getType()); $main->device->reset(['type' => Constants\DeviceType::MOBILE, 'subtype' => Constants\DeviceSubType::SMART]); $this->assertEquals('mobile:smart', $main->getType()); $main->device->reset(['type' => Constants\DeviceType::MOBILE, 'subtype' => Constants\DeviceSubType::FEATURE]); $this->assertEquals('mobile:feature', $main->getType()); }
function hydrateWhichbrowser($data, array $row, array $headers) { if (isset($row['engine']) || isset($row['features']) || isset($row['useragent'])) { throw new \Exception('client detection...'); } $data['resRawResult'] = serialize($row); $result = $row['result']; /* * Hydrate... */ $main = new Main(); if (isset($result['browser'])) { $toUse = []; foreach ($result['browser'] as $key => $value) { if ($key == 'name') { $toUse['name'] = $value; } elseif ($key == 'type') { $toUse['type'] = $value; } elseif ($key == 'alias') { $toUse['alias'] = $value; } elseif ($key == 'version') { $toUse['version'] = getWhichbrowserVersion($value); } elseif ($key == 'using') { $usingToUse = []; if (!is_array($value)) { $usingToUse['name'] = $value; } if (isset($value['name'])) { $usingToUse['name'] = $value['name']; } if (isset($value['version'])) { $usingToUse['version'] = getWhichbrowserVersion($value['version']); } $toUse['using'] = new Using($usingToUse); } elseif ($key == 'family') { $familyToUse = []; if (!is_array($value)) { $familyToUse['name'] = $value; } if (isset($value['name'])) { $familyToUse['name'] = $value['name']; } if (isset($value['version'])) { $familyToUse['version'] = getWhichbrowserVersion($value['version']); } $toUse['family'] = new Family($familyToUse); } else { throw new \Exception('unknown key: ' . $key . ' / ' . print_r($value, true)); } } $main->browser->set($toUse); } if (isset($result['engine'])) { $toUse = []; foreach ($result['engine'] as $key => $value) { if ($key == 'name') { $toUse['name'] = $value; } elseif ($key == 'version') { $toUse['version'] = getWhichbrowserVersion($value); } else { throw new \Exception('unknown key: ' . $key . ' / ' . print_r($value, true)); } } $main->engine->set($toUse); } if (isset($result['os'])) { $toUse = []; foreach ($result['os'] as $key => $value) { if ($key == 'name') { $toUse['name'] = $value; } elseif ($key == 'alias') { $toUse['alias'] = $value; } elseif ($key == 'family') { $familyToUse = []; if (!is_array($value)) { $familyToUse['name'] = $value; } if (isset($value['name'])) { $familyToUse['name'] = $value['name']; } if (isset($value['version'])) { $familyToUse['version'] = getWhichbrowserVersion($value['version']); } $toUse['family'] = new Family($familyToUse); } elseif ($key == 'version') { $toUse['version'] = getWhichbrowserVersion($value); } else { throw new \Exception('unknown key: ' . $key . ' / ' . print_r($value, true)); } } $main->os->set($toUse); } if (isset($result['device'])) { $toUse = []; foreach ($result['device'] as $key => $value) { if ($key == 'type') { $toUse['type'] = $value; } elseif ($key == 'subtype') { $toUse['subtype'] = $value; } elseif ($key == 'manufacturer') { $toUse['manufacturer'] = $value; } elseif ($key == 'model') { $toUse['model'] = $value; } elseif ($key == 'series') { $toUse['series'] = $value; } elseif ($key == 'carrier') { $toUse['carrier'] = $value; } else { throw new \Exception('unknown key: ' . $key . ' / ' . $value); } } $main->device->setIdentification($toUse); } if (isset($result['camouflage'])) { $main->camouflage = $result['camouflage']; } $resultArray = $main->toArray(); $provider = new WhichBrowser(); $resultParser = $provider->parse($headers['User-Agent'], $headers); $compare1 = $main->toArray(); $compare2 = $resultParser->getProviderResultRaw(); if ($compare1 !== $compare2) { if (count($headers) > 1) { echo 'O'; } else { echo 'E'; } } /* * convert to our result */ if ($main->getType() === 'bot') { $data['resBotIsBot'] = 1; if ($main->browser->getName() != '') { $data['resBotName'] = $main->browser->getName(); } return $data; } if ($main->browser->getName() != '') { $data['resBrowserName'] = $main->browser->getName(); if ($main->browser->getVersion() != '') { $data['resBrowserVersion'] = $main->browser->getVersion(); } } elseif (isset($main->browser->using) && $main->browser->using instanceof \WhichBrowser\Model\Using && $main->browser->using->getName() != '') { $data['resBrowserName'] = $main->browser->using->getName(); if ($main->browser->using->getVersion() != '') { $data['resBrowserVersion'] = $main->browser->using->getVersion(); } } if ($main->engine->getName() != '') { $data['resEngineName'] = $main->engine->getName(); } if ($main->engine->getVersion() != '') { $data['resEngineVersion'] = $main->engine->getVersion(); } if ($main->os->getName() != '') { $data['resOsName'] = $main->os->getName(); } if ($main->os->getVersion() != '') { $data['resOsVersion'] = $main->os->getVersion(); } if ($main->device->getModel() != '') { $data['resDeviceModel'] = $main->device->getModel(); } if ($main->device->getManufacturer() != '') { $data['resDeviceBrand'] = $main->device->getManufacturer(); } if ($main->getType() != '') { $data['resDeviceType'] = $main->getType(); } if ($main->isMobile() != '') { $data['resDeviceIsMobile'] = $main->isMobile(); } return $data; }