DeviceDetector\DeviceDetector::getInfoFromUserAgent PHP Method

getInfoFromUserAgent() public static method

ATTENTION: Use that method only for testing or very small applications To get fast results from DeviceDetector you need to make your own implementation, that should use one of the caching mechanisms. See README.md for more information.
Deprecation:
public static getInfoFromUserAgent ( string $ua ) : array
$ua string UserAgent to parse
return array
    public static function getInfoFromUserAgent($ua)
    {
        $deviceDetector = new DeviceDetector($ua);
        $deviceDetector->parse();
        if ($deviceDetector->isBot()) {
            return array('user_agent' => $deviceDetector->getUserAgent(), 'bot' => $deviceDetector->getBot());
        }
        $osFamily = OperatingSystem::getOsFamily($deviceDetector->getOs('short_name'));
        $browserFamily = \DeviceDetector\Parser\Client\Browser::getBrowserFamily($deviceDetector->getClient('short_name'));
        $processed = array('user_agent' => $deviceDetector->getUserAgent(), 'os' => $deviceDetector->getOs(), 'client' => $deviceDetector->getClient(), 'device' => array('type' => $deviceDetector->getDeviceName(), 'brand' => $deviceDetector->getBrand(), 'model' => $deviceDetector->getModel()), 'os_family' => $osFamily !== false ? $osFamily : 'Unknown', 'browser_family' => $browserFamily !== false ? $browserFamily : 'Unknown');
        return $processed;
    }

Usage Example

Example #1
0
 /**
  * @dataProvider getFixtures
  */
 public function testParse($fixtureData)
 {
     $ua = $fixtureData['user_agent'];
     DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);
     $uaInfo = DeviceDetector::getInfoFromUserAgent($ua);
     $this->assertEquals($fixtureData, $uaInfo);
 }
All Usage Examples Of DeviceDetector\DeviceDetector::getInfoFromUserAgent