Commit 894f4017 authored by Tomáš Pospíšil's avatar Tomáš Pospíšil
Browse files

Fix WebSwitcherUrls for cli

parent 3b8d511b
......@@ -28,11 +28,11 @@ final class Registrator
public static function getInstance(string $compileDir, string $cacheDir): Registrator
{
if (Registrator::$instance === null) {
Registrator::$instance = new self($compileDir, $cacheDir);
if (self::$instance === null) {
self::$instance = new self($compileDir, $cacheDir);
}
return Registrator::$instance;
return self::$instance;
}
public function registerDebugger(string $errorDir, string $emailDeveloper): Registrator
......@@ -42,12 +42,12 @@ final class Registrator
Debugger::$strictMode = true;
Debugger::$maxLength = 1024;
Debugger::$maxDepth = 5;
Debugger::enable("42@84.42.168.182,42@185.156.123.46", realpath($errorDir), Strings::replace($emailDeveloper, '/,;/', ','));
Debugger::enable('42@84.42.168.182,42@185.156.123.46', realpath($errorDir), Strings::replace($emailDeveloper, '/,;/', ','));
return $this;
}
public function registerAll(Smarty $smarty, WebSwitcherUrls $urls): Registrator
public function registerAll(Tools\TraceableSmarty $smarty, WebSwitcherUrls $urls): Registrator
{
if (Debugger::isEnabled()) {
$this->registerDBProfiler();
......@@ -108,7 +108,7 @@ final class Registrator
private function addPanel(string $method, callable $panelCreator): void
{
if (!array_key_exists($method, $this->registeredPanels) && Debugger::isEnabled()) {
if (PHP_SAPI !== 'cli' && !array_key_exists($method, $this->registeredPanels) && Debugger::isEnabled()) {
$panel = $panelCreator();
assert($panel instanceof IBarPanel);
$this->registeredPanels[$method] = $panel;
......
......@@ -26,7 +26,7 @@ final class WebSwitcherUrls
public function __construct(string $local, string $testing, string $live)
{
$current = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$current = $this->currentUrl();
$host = parse_url($current, PHP_URL_HOST);
......@@ -76,4 +76,19 @@ final class WebSwitcherUrls
return $this->current ?? '?';
}
/**
* @return string
*/
private function currentUrl(): string
{
$protocol = 'http';
if (filter_input(INPUT_SERVER, 'HTTPS')) {
$protocol .= 's';
}
$httpHost = filter_input(INPUT_SERVER, 'HTTP_HOST') ?? '';
$requestUri = filter_input(INPUT_SERVER, 'REQUEST_URI') ?? '';
return $protocol . '://' . $httpHost . $requestUri;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment