public function getPatterns($userAgent)
{
$starts = Pattern::getHashForPattern($userAgent, true);
$length = strlen($userAgent);
// add special key to fall back to the default browser
$starts[] = str_repeat('z', 32);
// get patterns, first for the given browser and if that is not found,
// for the default browser (with a special key)
foreach ($starts as $tmpStart) {
$tmpSubkey = SubKey::getPatternCacheSubkey($tmpStart);
if (!$this->cache->hasItem('browscap.patterns.' . $tmpSubkey, true)) {
$this->logger->debug('cache key "browscap.patterns.' . $tmpSubkey . '" not found');
continue;
}
$success = null;
$file = $this->cache->getItem('browscap.patterns.' . $tmpSubkey, true, $success);
if (!$success) {
$this->logger->debug('cache key "browscap.patterns.' . $tmpSubkey . '" not found');
continue;
}
if (!is_array($file) || !count($file)) {
$this->logger->debug('cache key "browscap.patterns.' . $tmpSubkey . '" was empty');
continue;
}
$found = false;
foreach ($file as $buffer) {
list($tmpBuffer, $len, $patterns) = explode("\t", $buffer, 3);
if ($tmpBuffer === $tmpStart) {
if ($len <= $length) {
(yield trim($patterns));
}
$found = true;
} elseif ($found === true) {
break;
}
}
}
(yield '');
}