=') && self::isChromiumVersionAtLeast(67, $userAgent, '<='); } /** * Detect iOS version. * * @param int $major The major version to test. * @param str $userAgent The User Agent. * @return bool */ private static function isIosVersion($major, $userAgent) { $regex = "/\(iP.+; CPU .*OS (\d+)[_\d]*.*\) AppleWebKit\//"; $matched = []; if (preg_match($regex, $userAgent, $matched)) { // Extract digits from first capturing group. $version = (int) $matched[1]; return version_compare($version, $major, '<='); } return FALSE; } /** * Detect MacOS version. * * @param int $major The major version to test. * @param int $minor The minor version to test. * @param str $userAgent The User Agent. * @return bool */ private static function isMacosxVersion($major, $minor, $userAgent) { $regex = "/\(Macintosh;.*Mac OS X (\d+)_(\d+)[_\d]*.*\) AppleWebKit\//"; $matched = []; if (preg_match($regex, $userAgent, $matched)) { // Extract digits from first and second capturing groups. return version_compare((int) $matched[1], $major, '=') && version_compare((int) $matched[2], $minor, '<='); } return FALSE; } /** * Detect MacOS Safari. * * @param str $userAgent The User Agent. * @return bool */ private static function isSafari($userAgent) { $regex = "/Version\/.* Safari\//"; return preg_match($regex, $userAgent) && !self::isChromiumBased($userAgent); } /** * Detect MacOS embedded browser. * * @param str $userAgent The User Agent. * @return FALSE|int */ private static function isMacEmbeddedBrowser($userAgent) { $regex = "/^Mozilla\/[\.\d]+ \(Macintosh;.*Mac OS X [_\d]+\) AppleWebKit\/[\.\d]+ \(KHTML, like Gecko\)$/"; return preg_match($regex, $userAgent); } /** * Detect if browser is Chromium based. * * @param str $userAgent The User Agent. * @return FALSE|int */ private static function isChromiumBased($userAgent) { $regex = "/Chrom(e|ium)/"; return preg_match($regex, $userAgent); } /** * Detect if Chromium version meets requirements. * * @param int $major The major version to test. * @param str $userAgent The User Agent. * @param str $operator * @return bool|int */ private static function isChromiumVersionAtLeast($major, $userAgent, $operator) { $regex = "/Chrom[^ \/]+\/(\d+)[\.\d]* /"; $matched = []; if (preg_match($regex, $userAgent, $matched)) { // Extract digits from first capturing group. $version = (int) $matched[1]; return version_compare($version, $major, $operator); } return FALSE; } /** * Detect UCBrowser. * * @param str $userAgent The User Agent. * @return FALSE|int */ private static function isUcBrowser($userAgent) { $regex = "/UCBrowser\//"; return preg_match($regex, $userAgent); } /** * Detect if UCBrowser version meets requirements. * * @param int $major The major version to test. * @param int $minor The minor version to test. * @param int $build The build version to test. * @param str $userAgent The User Agent. * @return bool|int */ private static function isUcBrowserVersionAtLeast($major, $minor, $build, $userAgent) { $regex = "/UCBrowser\/(\d+)\.(\d+)\.(\d+)[\.\d]* /"; $matched = []; if (preg_match($regex, $userAgent, $matched)) { // Extract digits from three capturing groups. $majorVersion = (int) $matched[1]; $minorVersion = (int) $matched[2]; $buildVersion = (int) $matched[3]; if (version_compare($majorVersion, $major, '>=')) { if (version_compare($minorVersion, $minor, '>=')) { return version_compare($buildVersion, $build, '>='); } } } return FALSE; } }