Team Ai
Apppublic

errorcode418/php

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
DeviceParser.php38 linesDownload Raw Back to src
1<?php2/**3 * ua-parser4 *5 * Copyright (c) 2011-2013 Dave Olsen, http://dmolsen.com6 * Copyright (c) 2013-2014 Lars Strojny, http://usrportage.de7 *8 * Released under the MIT license9 */10namespace UAParser;11 12use UAParser\Result\Device;13 14class DeviceParser extends AbstractParser15{16    /**17     * Attempts to see if the user agent matches a device regex from regexes.php18     *19     * @param string $userAgent a user agent string to test20     * @return Device21     */22    public function parseDevice($userAgent)23    {24        $device = new Device();25 26        list($regex, $matches) = self::tryMatch($this->regexes['device_parsers'], $userAgent);27 28        if ($matches) {29            $device->family = self::multiReplace($regex, 'device_replacement', $matches[1], $matches);30            $device->brand  = self::multiReplace($regex, 'brand_replacement', null, $matches);31            $deviceModelDefault = $matches[1] !== 'Other' ? $matches[1] : null;32            $device->model  = self::multiReplace($regex, 'model_replacement', $deviceModelDefault, $matches);33        }34 35        return $device;36    }37}38