Skip to content

Commit

Permalink
AppKernel. HTTP_HOST для CLI (из переменных окружения).
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Aug 3, 2021
1 parent 5f8de40 commit 626b8ac
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/Services/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function getKernelParameters(): array
'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
'kernel.cache_dir' => $this->getCacheDir(),
'kernel.logs_dir' => $this->getLogDir(),
'kernel.http.host' => $_SERVER['HTTP_HOST'],
'kernel.http.host' => $this->getHttpHost(),
'kernel.site.host' => $this->getSiteHost(),
'kernel.schema' => $this->getSchema(),
'kernel.bundles' => $bundlesMetaData['kernel.bundles'],
Expand Down Expand Up @@ -313,8 +313,33 @@ private function getSiteHost() : string
*/
private function getSchema() : string
{
return (!empty($_SERVER['HTTPS'])
&& ($_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443)
) ? 'https://' : 'http://';
if (!array_key_exists('HTTPS', $_SERVER)
&& (array_key_exists('HTTPS', $_ENV) && $_ENV['HTTPS'] === 'off')) {
return 'http://';
}

if (!array_key_exists('HTTPS', $_SERVER)
&& (array_key_exists('HTTPS', $_ENV) && $_ENV['HTTPS'] === 'on')) {
return 'https://';
}

return $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443 ? 'https://' : 'http://';
}

/**
* HTTP_HOST с учетом CLI. Если пусто, то берется из переменной окружения.
*
* @return string
*
* @since 03.08.2021
*/
private function getHttpHost() : string
{
if (!array_key_exists('HTTP_HOST', $_SERVER)
&& array_key_exists('HTTP_HOST', $_ENV)) {
return $_ENV['HTTP_HOST'];
}

return (string)$_SERVER['HTTP_HOST'];
}
}

0 comments on commit 626b8ac

Please sign in to comment.