errorcode418/php
0
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\UserAgent;13 14class UserAgentParser extends AbstractParser15{16 /**17 * Attempts to see if the user agent matches a user agents regex from regexes.php18 *19 * @param string $userAgent a user agent string to test20 * @param array $jsParseBits21 * @return UserAgent22 */23 public function parseUserAgent($userAgent, array $jsParseBits = array())24 {25 $ua = new UserAgent();26 27 if (isset($jsParseBits['js_user_agent_family']) && $jsParseBits['js_user_agent_family']) {28 29 $ua->family = $jsParseBits['js_user_agent_family'];30 $ua->major = $jsParseBits['js_user_agent_v1'];31 $ua->minor = $jsParseBits['js_user_agent_v2'];32 $ua->patch = $jsParseBits['js_user_agent_v3'];33 34 } else {35 36 list($regex, $matches) = self::tryMatch($this->regexes['user_agent_parsers'], $userAgent);37 38 if ($matches) {39 $ua->family = self::multiReplace($regex, 'family_replacement', $matches[1], $matches);40 $ua->major = self::multiReplace($regex, 'v1_replacement', $matches[2], $matches);41 $ua->minor = self::multiReplace($regex, 'v2_replacement', $matches[3], $matches);42 $ua->patch = self::multiReplace($regex, 'v3_replacement', $matches[4], $matches);43 }44 }45 46 if (isset($jsParseBits['js_user_agent_string'])) {47 $jsUserAgentString = $jsParseBits['js_user_agent_string'];48 if (strpos($jsUserAgentString, 'Chrome/') !== false && strpos($userAgent, 'chromeframe') !== false) {49 $override = $this->parseUserAgent($jsUserAgentString);50 $ua->family = sprintf('Chrome Frame (%s %s)', $ua->family, $ua->major);51 $ua->major = $override->major;52 $ua->minor = $override->minor;53 $ua->patch = $override->patch;54 }55 }56 57 return $ua;58 }59 60}61 