- Модуль: imconnector
- Путь к файлу: ~/bitrix/modules/imconnector/lib/library.php
- Класс: BitrixImConnectorLibrary
- Вызов: Library::getCurrentServerUrl
static function getCurrentServerUrl(): string
{
static $url;
if ($url === null)
{
$context = BitrixMainApplication::getInstance()->getContext();
$scheme = $context->getRequest()->isHttps() ? 'https' : 'http';
$server = $context->getServer();
$domain = Option::get('main', 'server_name', '');
if (empty($domain))
{
$domain = $server->getServerName();
}
if (preg_match('/^(?.+):(?d+)$/', $domain, $matches))
{
$domain = $matches['domain'];
$port = (int)$matches['port'];
}
else
{
$port = (int)$server->getServerPort();
}
$port = in_array($port, [0, 80, 443]) ? '' : ':'.$port;
$url = $scheme.'://'.$domain.$port;
}
return $url;
}