97 $this->_eventManager = $eventManager;
98 $this->_areaList = $areaList;
101 $this->_configLoader = $configLoader;
102 $this->_state = $state;
114 private function getLogger()
116 if (!$this->logger instanceof \Psr\
Log\LoggerInterface) {
119 return $this->logger;
130 $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
131 $this->_state->setAreaCode($areaCode);
132 $this->_objectManager->configure($this->_configLoader->load($areaCode));
134 $frontController = $this->_objectManager->get(\
Magento\Framework\
App\FrontControllerInterface::class);
135 $result = $frontController->dispatch($this->_request);
137 if (
$result instanceof ResultInterface) {
138 $this->registry->register(
'use_page_cache_plugin',
true,
true);
139 $result->renderResult($this->_response);
143 throw new \InvalidArgumentException(
'Invalid return type');
147 $this->_eventManager->dispatch(
'controller_front_send_response_before', $eventParams);
157 || $this->handleBootstrapErrors(
$bootstrap, $exception)
158 || $this->handleSessionException($exception)
159 || $this->handleInitException($exception)
160 || $this->handleGenericReport(
$bootstrap, $exception);
176 $this->redirectToSetup(
$bootstrap, $exception);
178 }
catch (\Exception $e) {
182 $this->_response->setHttpResponseCode(500);
183 $this->_response->setHeader(
'Content-Type',
'text/plain');
184 $this->_response->setBody($this->buildContentFromException($exception));
185 $this->_response->sendResponse();
197 private function buildContentFromException(\Exception $exception)
202 $exceptions[] = $exception;
203 }
while ($exception = $exception->getPrevious());
205 $buffer = sprintf(
"%d exception(s):\n", count($exceptions));
207 foreach ($exceptions as
$index => $exception) {
208 $buffer .= sprintf(
"Exception #%d (%s): %s\n",
$index, get_class($exception), $exception->getMessage());
211 foreach ($exceptions as
$index => $exception) {
213 "\nException #%d (%s): %s\n%s\n",
215 get_class($exception),
216 $exception->getMessage(),
217 $exception->getTraceAsString()
232 private function redirectToSetup(Bootstrap
$bootstrap, \Exception $exception)
234 $setupInfo =
new SetupInfo(
$bootstrap->getParams());
235 $projectRoot = $this->_filesystem->getDirectoryRead(
DirectoryList::ROOT)->getAbsolutePath();
236 if ($setupInfo->isAvailable()) {
237 $this->_response->setRedirect($setupInfo->getUrl());
238 $this->_response->sendHeaders();
240 $newMessage = $exception->getMessage() .
"\nNOTE: You cannot install Magento using the Setup Wizard " 241 .
"because the Magento setup directory cannot be accessed. \n" 242 .
'You can install Magento using either the command line or you must restore access ' 243 .
'to the following directory: ' . $setupInfo->getDir($projectRoot) .
"\n";
245 throw new \Exception($newMessage, 0, $exception);
256 private function handleBootstrapErrors(Bootstrap
$bootstrap, \Exception &$exception)
260 require $this->_filesystem->getDirectoryRead(
DirectoryList::PUB)->getAbsolutePath(
'errors/503.php');
265 $this->redirectToSetup(
$bootstrap, $exception);
267 }
catch (\Exception $e) {
280 private function handleSessionException(\Exception $exception)
282 if ($exception instanceof \
Magento\Framework\Exception\SessionException) {
283 $this->_response->setRedirect($this->_request->getDistroBaseUrl());
284 $this->_response->sendHeaders();
296 private function handleInitException(\Exception $exception)
298 if ($exception instanceof \
Magento\Framework\Exception\State\InitException) {
299 $this->getLogger()->critical($exception);
300 require $this->_filesystem->getDirectoryRead(
DirectoryList::PUB)->getAbsolutePath(
'errors/404.php');
313 private function handleGenericReport(Bootstrap
$bootstrap, \Exception $exception)
315 $reportData = [$exception->getMessage(), $exception->getTraceAsString()];
317 if (isset(
$params[
'REQUEST_URI'])) {
318 $reportData[
'url'] =
$params[
'REQUEST_URI'];
320 if (isset(
$params[
'SCRIPT_NAME'])) {
321 $reportData[
'script_name'] =
$params[
'SCRIPT_NAME'];
323 require $this->_filesystem->getDirectoryRead(
DirectoryList::PUB)->getAbsolutePath(
'errors/report.php');
elseif(isset( $params[ 'redirect_parent']))
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, Event\Manager $eventManager, AreaList $areaList, RequestHttp $request, ResponseHttp $response, ConfigLoaderInterface $configLoader, State $state, Filesystem $filesystem, \Magento\Framework\Registry $registry)
catchException(Bootstrap $bootstrap, \Exception $exception)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]