public static function isActiveCabinKey(string $cabinKey = '*', bool $https_only = false, string $scheme = '', string $activeHost = '', string $uri = '') : bool
{
if (empty($uri)) {
$uri = $_SERVER['REQUEST_URI'] ?? '';
}
if (empty($scheme)) {
$scheme = self::isHTTPSConnection() ? 'https' : 'http';
}
if ($cabinKey === '*') {
return true;
}
if ($cabinKey[0] === '*') {
if ($cabinKey[1] === '/') {
// */some_dir/
$pattern = \preg_quote(Binary::safeSubstr($cabinKey, 2), '#');
if (\preg_match('#^/' . $pattern . '#', $uri) === 1) {
return $https_only ? self::forceHTTPS() : true;
}
}
} else {
if (empty($activeHost)) {
$activeHost = $_SERVER['HTTP_HOST'] ?? 'localhost';
}
$pos = \strpos($cabinKey, '/');
if ($pos === false && \preg_match('#^' . \preg_quote($cabinKey, '#') . '#', $uri)) {
return $https_only ? self::forceHTTPS($scheme) : true;
} elseif ($pos !== false) {
$sub = Binary::safeSubstr($cabinKey, $pos);
$host = Binary::safeSubstr($cabinKey, 0, $pos);
if (\strtolower($activeHost) === \strtolower($host) && \preg_match('#^' . \preg_quote($sub, '#') . '#', $uri)) {
return $https_only ? self::forceHTTPS($scheme) : true;
}
} elseif (\strtolower($activeHost) === \strtolower($cabinKey)) {
return $https_only ? self::forceHTTPS($scheme) : true;
}
}
return false;
}