See also: https://github.com/WhichBrowser/Parser
Author: Martin Keckeis (martin.keckeis1@gmail.com)
Author: Niels Leenheer (niels@leenheer.nl)
Inheritance: extends AbstractProvider
 public function testParser()
 {
     $provider = new WhichBrowser();
     $this->assertInstanceOf('WhichBrowser\\Parser', $provider->getParser([]));
 }
 public function testRealResultDevice()
 {
     $provider = new WhichBrowser();
     $result = $provider->parse('Mozilla/5.0 (Linux; Android 4.3; SCH-R970C Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.3');
     $this->assertEquals(['browser' => ['name' => 'Chrome', 'version' => ['major' => 34, 'minor' => null, 'patch' => null, 'alias' => null, 'complete' => '34']], 'renderingEngine' => ['name' => 'Blink', 'version' => ['major' => null, 'minor' => null, 'patch' => null, 'alias' => null, 'complete' => null]], 'operatingSystem' => ['name' => 'Android', 'version' => ['major' => 4, 'minor' => 3, 'patch' => null, 'alias' => null, 'complete' => '4.3']], 'device' => ['model' => 'Galaxy S4', 'brand' => 'Samsung', 'type' => 'mobile:smart', 'isMobile' => true, 'isTouch' => null], 'bot' => ['isBot' => null, 'name' => null, 'type' => null]], $result->toArray());
     /*
      * Test the raw result
      */
     $rawResult = $result->getProviderResultRaw();
     $this->assertEquals(['browser' => ['name' => 'Chrome', 'version' => '34', 'type' => 'browser'], 'engine' => ['name' => 'Blink'], 'os' => ['name' => 'Android', 'version' => '4.3'], 'device' => ['type' => 'mobile', 'subtype' => 'smart', 'manufacturer' => 'Samsung', 'model' => 'Galaxy S4']], $rawResult);
 }
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;
}