diff --git a/index.php b/index.php index 9ac7f6ffa71b2..e8529da2f4ac5 100644 --- a/index.php +++ b/index.php @@ -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); diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index 717b810cffd29..99d1e8cdec606 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -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 * @@ -383,7 +392,7 @@ private function initErrorHandler() $handler = new ErrorHandler(); set_error_handler([$handler, 'handler']); } - + /** * Getter for error code * @@ -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])) { @@ -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; } /** @@ -425,7 +443,6 @@ public function isDeveloperMode() */ protected function terminate(\Exception $e) { - if ($this->isDeveloperMode()) { echo $e; } else { diff --git a/pub/index.php b/pub/index.php index 612e190719053..3fddf4d96af7d 100644 --- a/pub/index.php +++ b/pub/index.php @@ -25,8 +25,8 @@ } $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'], @@ -34,7 +34,9 @@ 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);