Skip to content

[TASK] Dynamically set upward server variables #23126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
}

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$_SERVER['MAGENTO_BACKEND_URL'] = $bootstrap->getMagentoBackendUrl();
$_SERVER['NODE_ENV'] = $bootstrap->getMode();
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);
29 changes: 23 additions & 6 deletions lib/internal/Magento/Framework/App/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ public function createApplication($type, $arguments = [])
}
}

/**
* @return string
*/
public function getMagentoBackendUrl(): string
{
$protocol = isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] === 'on' ? 'https' : 'http';
return "{$protocol}://{$_SERVER['HTTP_HOST']}";
}

/**
* Runs an application
*
Expand Down Expand Up @@ -383,7 +392,7 @@ private function initErrorHandler()
$handler = new ErrorHandler();
set_error_handler([$handler, 'handler']);
}

/**
* Getter for error code
*
Expand All @@ -395,11 +404,11 @@ public function getErrorCode()
}

/**
* Checks whether developer mode is set in the initialization parameters
* Returns the mode from the initialization parameters
*
* @return bool
* @return mixed|string
*/
public function isDeveloperMode()
public function getMode()
{
$mode = 'default';
if (isset($this->server[State::PARAM_MODE])) {
Expand All @@ -411,8 +420,17 @@ public function isDeveloperMode()
$mode = $configMode;
}
}
return $mode;
}

return $mode == State::MODE_DEVELOPER;
/**
* Checks whether developer mode is set in the initialization parameters
*
* @return bool
*/
public function isDeveloperMode()
{
return $this->getMode() == State::MODE_DEVELOPER;
}

/**
Expand All @@ -425,7 +443,6 @@ public function isDeveloperMode()
*/
protected function terminate(\Exception $e)
{

if ($this->isDeveloperMode()) {
echo $e;
} else {
Expand Down
8 changes: 5 additions & 3 deletions pub/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
}

$params = $_SERVER;
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = array_replace_recursive(
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] ?? [],
$_SERVER[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = array_replace_recursive(
$_SERVER[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] ?? [],
[
DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
]
);
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$_SERVER['MAGENTO_BACKEND_URL'] = $bootstrap->getMagentoBackendUrl();
$_SERVER['NODE_ENV'] = $bootstrap->getMode();
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);