File: test.php

package info (click to toggle)
matomo-device-detector 6.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,684 kB
  • sloc: php: 7,758; xml: 79; makefile: 15; sh: 3
file content (41 lines) | stat: -rw-r--r-- 906 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

/**
 * Device Detector - The Universal Device Detection library for parsing User Agents
 *
 * @link https://matomo.org
 *
 * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
 */

declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\AbstractDeviceParser;

if ('cli' === PHP_SAPI) {
    if (isset($argv[1])) {
        $userAgent = $argv[1];
    }
} else {
    $userAgent = $_GET['ua'] ?? $_SERVER['HTTP_USER_AGENT'];
}

AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE);

$result = DeviceDetector::getInfoFromUserAgent($userAgent);

if ('cli' === PHP_SAPI) {
    echo Spyc::YAMLDump($result, 2, 0);
    exit(0);
}

echo '<form><input type="text" name="ua" /><input type="submit" /></form>';

echo '<pre>';

echo Spyc::YAMLDump($result, 2, 0);

echo '</pre>';