Search for a certain key in the rules array.
If the key is found the try to match the corresponding
regex agains the User-agent.

@param string $key
@param null $userAgent deprecated
@return mixed
176863
private function matchUAAgainstKey($key, $userAgent = null){

        // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
        $key = strtolower($key);
        $_rules = array_change_key_case($this->getRules());

        if(array_key_exists($key, $_rules)){
            if(empty($_rules[$key])){ return null; }
            return $this->match($_rules[$key], $userAgent);
        }

        return false;

    }
546520
public function applyConclusiveMatch($userAgent)
    {
        $tolerance = Utils::toleranceToRisDelimeter($userAgent);
        if ($tolerance !== false) {
            return $this->getDeviceIDFromRIS($userAgent, $tolerance);
        }

        $operaMiniIndex = Utils::indexOfOrLength($userAgent, 'Opera Mini');

        if ($operaMiniIndex !== false) {
            // Match up to the first '.' after 'Opera Mini'
            $tolerance = strpos($userAgent, '.', $operaMiniIndex);

            if ($tolerance !== false) {
                // +1 to match just after the '.'
                return $this->getDeviceIDFromRIS($userAgent, $tolerance + 1);
            }
        }

        $tolerance = Utils::firstSlash($userAgent);

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
781885
public function applyRecoveryMatch($userAgent)
    {
        if (Utils::checkIfContains($userAgent, 'SmartTV')) {
            return 'generic_smarttv_browser';
        }

        if (Utils::checkIfContains($userAgent, 'GoogleTV')) {
            return 'generic_smarttv_googletv_browser';
        }

        if (Utils::checkIfContains($userAgent, 'AppleTV')) {
            return 'generic_smarttv_appletv_browser';
        }

        if (Utils::checkIfContains($userAgent, 'Boxee')) {
            return 'generic_smarttv_boxeebox_browser';
        }

        if (Utils::checkIfContains($userAgent, 'CrKey')) {
            return 'generic_smarttv_chromecast';
        }

        return 'generic_smarttv_browser';
    }
1174017
public function applyConclusiveMatch($userAgent)
    {
        if (Utils::checkIfContains($userAgent, ' Build/')) {
            return $this->getDeviceIDFromRIS($userAgent, Utils::indexOfOrLength($userAgent, ' Build/'));
        }
        $prefixes = array(
            'Opera/9.80 (J2ME/MIDP; Opera Mini/5' => 'uabait_opera_mini_android_v50',
            'Opera/9.80 (Android; Opera Mini/5.0' => 'uabait_opera_mini_android_v50',
            'Opera/9.80 (Android; Opera Mini/5.1' => 'uabait_opera_mini_android_v51',
        );
        foreach ($prefixes as $prefix => $defaultID) {
            if (Utils::checkIfStartsWith($userAgent, $prefix)) {
                // If RIS returns a non-generic match, return it, else, return the default
                $tolerance = strlen($prefix);
                $deviceID  = $this->getDeviceIDFromRIS($userAgent, $tolerance);

                if ($deviceID === WurflConstants::NO_MATCH) {
                    return $defaultID;
                }

                return $deviceID;
            }
        }

        return WurflConstants::NO_MATCH;
    }
463296
public function getRules($userAgent = null)
    {
        // return all rules
        if ($userAgent === null) {
            return $this->rules;
        }
        $this->setUserAgent($userAgent);
        if (isset($this->rules[$this->userAgentMatch])) {
            return $this->rules[$this->userAgentMatch];
        }
        $this->log[] = 'Rules not found for the given User-Agent';
        return array();
    }
947669
public function getBrowser(string $userAgent) : ?FormatterInterface
    {
        $userAgent = strtolower($userAgent);
        $formatter = null;

        foreach ($this->patternHelper->getPatterns($userAgent) as $patterns) {
            $patternToMatch = '/^(?:' . str_replace("\t", ')|(?:', $patterns) . ')$/i';

            if (! preg_match($patternToMatch, $userAgent)) {
                continue;
            }

            // strtok() requires less memory than explode()
            $pattern = strtok($patterns, "\t");

            while (false !== $pattern) {
                $pattern = str_replace('[\d]', '(\d)', $pattern);
                $quotedPattern = '/^' . $pattern . '$/i';
                $matches = [];

                if (preg_match($quotedPattern, $userAgent, $matches)) {
                    // Insert the digits back into the pattern, so that we can search the settings for it
                    if (1 < count($matches)) {
                        array_shift($matches);
                        foreach ($matches as $oneMatch) {
                            $numPos = strpos($pattern, '(\d)');
                            $pattern = substr_replace($pattern, $oneMatch, $numPos, 4);
                        }
                    }

                    // Try to get settings - as digits have been replaced to speed up the pattern search (up to 90 faster),
                    // we won't always find the data in the first step - so check if settings have been found and if not,
                    // search for the next pattern.
                    $settings = $this->dataHelper->getSettings($pattern);

                    if (0 < count($settings)) {
                        $formatter = $this->formatter;
                        $formatter->setData($settings);

                        break 2;
                    }
                }

                $pattern = strtok("\t");
            }
        }

        return $formatter;
    }
1000009
public function applyRecoveryMatch($userAgent)
    {
        $androidVersion = str_replace('.', '_', AndroidHandler::getAndroidVersion($userAgent));
        $deviceID       = 'generic_android_ver' . $androidVersion . '_ucweb';

        if (in_array($deviceID, self::$constantIDs)) {
            return $deviceID;
        } else {
            return 'generic_android_ver2_0_ucweb';
        }
    }
1139952
public function lookForMatchingUserAgent($userAgent)
    {
        $tolerance = Utils::firstSlash($userAgent);

        return Utils::risMatch($this->userAgents, $userAgent, $tolerance);
    }
397057
public function detect($userAgent = null, $validate = false) {
		$this->report = $this->_report;
		
		if($userAgent === null) {
			$userAgent =  $_SERVER['HTTP_USER_AGENT'];
		}
		
		if (!is_string($userAgent)) {
			return false;	
		}
		$this->report['ua'] = $userAgent;
		preg_match_all($this->_patterns['parser'],$userAgent,$this->data);
		
		$this->data = (isset($this->data[0])) ? $this->data[0] : false;
		
		//$this->isValid == false;
		if ($this->data === false) {
			return false;
		}
		
		try {
			$this->checkProduct();
			$this->checkOs();
			
		} catch (Exception $e) {
			
		}
		
	
		return $this->report;
	}
942970
public static function isRobot($userAgent)
    {
        self::$isRobot = false;
        $userAgent     = strtolower($userAgent);

        foreach (self::$robots as $key) {
            if (strpos($userAgent, $key) !== false) {
                self::$isRobot = true;
                break;
            }
        }

        return self::$isRobot;
    }
1021165
public function applyConclusiveMatch($userAgent)
    {
        //High accuracy mode
        $tolerance = Utils::firstCloseParen($userAgent);

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
674474
public function getBrowser(string $userAgent = null)
    {
        // Check if an automatic update is required
        $this->autoUpdate();

        // If no user agent is set, try to get it from the HTTP headers
        if ($userAgent === null) {
            $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
        }

        // Get rwa Browscap data and return a formatted version, using the set Formatter
        $browscapData = $this->getParser()->getReader()->getBrowser($userAgent);
        return $this->getFormatter()->format($browscapData);
    }
458137
public function load(string $key, string $useragent = ''): array
    {
        if (!$this->initData->hasItem($key)) {
            throw new NotFoundException('the browser with key "' . $key . '" was not found');
        }

        $browserData = $this->initData->getItem($key);

        if (null === $browserData) {
            throw new NotFoundException('the browser with key "' . $key . '" was not found');
        }

        $engineKey = $browserData->engine;
        $engine    = null;

        if (null !== $engineKey) {
            try {
                $engine = $this->engineParser->load($engineKey, $useragent);
            } catch (NotFoundException $e) {
                $this->logger->warning($e);
            }
        }

        $browser = (new BrowserFactory($this->companyLoader, new VersionFactory(), new TypeLoader()))->fromArray($this->logger, (array) $browserData, $useragent);

        return [$browser, $engine];
    }
1273116
protected function matchUserAgent($regex)
    {
        // only match if useragent begins with given regex or there is no letter before it
        $regex = '/(?:^|[^A-Z0-9\-_]|[^A-Z0-9\-]_|sprd-)(?:' . str_replace('/', '\/', $regex) . ')/i';

        if (preg_match($regex, $this->userAgent, $matches)) {
            return $matches;
        }

        return false;
    }
875652
public function load(string $key, string $useragent = ''): array
    {
        if (!$this->initData->hasItem($key)) {
            throw new NotFoundException('the device with key "' . $key . '" was not found');
        }

        $deviceData = $this->initData->getItem($key);

        if (null === $deviceData) {
            throw new NotFoundException('the device with key "' . $key . '" was not found');
        }

        $platformKey = $deviceData->platform;
        $platform    = null;

        if (null !== $platformKey) {
            try {
                $platform = $this->platformParser->load($platformKey, $useragent);
            } catch (NotFoundException $e) {
                $this->logger->warning($e);
            }
        }

        $deviceFactory = new DeviceFactory(
            $this->companyLoader,
            new \UaDeviceType\TypeLoader(),
            new DisplayFactory(new \UaDisplaySize\TypeLoader())
        );
        $device = $deviceFactory->fromArray($this->logger, (array) $deviceData, $useragent);

        return [$device, $platform];
    }
942916
public function applyConclusiveMatch($userAgent)
    {
        $skyfireIndex = strpos($userAgent, 'Skyfire');

        // Matches the first decimal point after the Skyfire keyword: Skyfire/2.0
        return $this->getDeviceIDFromRIS($userAgent, Utils::indexOfOrLength($userAgent, '.', $skyfireIndex));
    }
1288230
protected function checkRules($rule, $path, $userAgent)
    {
        // check for disallowed http status code
        if ($this->checkHttpStatusCodeRule()) {
            return ($rule === self::DIRECTIVE_DISALLOW);
        }
        // Check each directive for rules, allowed by default
        $result = ($rule === self::DIRECTIVE_ALLOW);
        foreach (array(self::DIRECTIVE_DISALLOW, self::DIRECTIVE_ALLOW) as $directive) {
            if (isset($this->rules[$userAgent][$directive])) {
                foreach ($this->rules[$userAgent][$directive] as $robotRule) {
                    // check rule
                    if ($this->checkRuleSwitch($robotRule, $path)) {
                        // rule match
                        $result = ($rule === $directive);
                    }
                }
            }
        }
        return $result;
    }