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
Beispiel #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);
 }
 public function testGetInforFromUABot()
 {
     $expected = array('user_agent' => 'Googlebot/2.1 (http://www.googlebot.com/bot.html)', 'bot' => array('name' => 'Googlebot', 'category' => 'Search bot', 'url' => 'http://www.google.com/bot.html', 'producer' => array('name' => 'Google Inc.', 'url' => 'http://www.google.com')));
     $this->assertEquals($expected, DeviceDetector::getInfoFromUserAgent($expected['user_agent']));
 }
Beispiel #3
0
<?php

/**
 * Device Detector - The Universal Device Detection library for parsing User Agents
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
require __DIR__ . '/vendor/autoload.php';
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\DeviceParserAbstract;
if (isset($_GET['ua'])) {
    $userAgent = $_GET['ua'];
} else {
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
}
DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);
$result = DeviceDetector::getInfoFromUserAgent($userAgent);
echo '<form><input type="text" name="ua" /><input type="submit" /></form>';
echo "<pre>";
echo Spyc::YAMLDump($result, 2, 0);
echo "</pre>";