forked from ua-parser/uap-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceParser.php
37 lines (32 loc) · 1.09 KB
/
DeviceParser.php
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
<?php
/**
* ua-parser
*
* Copyright (c) 2011-2013 Dave Olsen, http://dmolsen.com
* Copyright (c) 2013-2014 Lars Strojny, http://usrportage.de
*
* Released under the MIT license
*/
namespace UAParser;
use UAParser\Result\Device;
class DeviceParser extends AbstractParser
{
/**
* Attempts to see if the user agent matches a device regex from regexes.php
*
* @param string $userAgent a user agent string to test
* @return Device
*/
public function parseDevice($userAgent)
{
$device = new Device();
list($regex, $matches) = $this->tryMatch($this->regexes['device_parsers'], $userAgent);
if ($matches) {
$device->family = $this->multiReplace($regex, 'device_replacement', $matches[1], $matches);
$device->brand = $this->multiReplace($regex, 'brand_replacement' , null, $matches);
$deviceModelDefault = $matches[1] != 'Other' ? $matches[1] : null;
$device->model = $this->multiReplace($regex, 'model_replacement' , $deviceModelDefault, $matches);
}
return $device;
}
}