forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Http.php
156 lines (145 loc) · 5.12 KB
/
Http.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Http application
*
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Magento\Framework\App;
use Magento\Framework\App\ObjectManager\ConfigLoader;
use Magento\Framework\App\Request\Http as RequestHttp;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\Event;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Http implements \Magento\Framework\AppInterface
{
/**
* @var \Magento\Framework\ObjectManager
*/
protected $_objectManager;
/**
* @var \Magento\Framework\Event\Manager
*/
protected $_eventManager;
/**
* @var AreaList
*/
protected $_areaList;
/**
* @var Request\Http
*/
protected $_request;
/**
* @var ConfigLoader
*/
protected $_configLoader;
/**
* @var State
*/
protected $_state;
/**
* @var Filesystem
*/
protected $_filesystem;
/**
* @var Response\Http
*/
protected $_response;
/**
* @param \Magento\Framework\ObjectManager $objectManager
* @param Event\Manager $eventManager
* @param AreaList $areaList
* @param RequestHttp $request
* @param ResponseHttp $response
* @param ConfigLoader $configLoader
* @param State $state
* @param Filesystem $filesystem
*/
public function __construct(
\Magento\Framework\ObjectManager $objectManager,
Event\Manager $eventManager,
AreaList $areaList,
RequestHttp $request,
ResponseHttp $response,
ConfigLoader $configLoader,
State $state,
Filesystem $filesystem
) {
$this->_objectManager = $objectManager;
$this->_eventManager = $eventManager;
$this->_areaList = $areaList;
$this->_request = $request;
$this->_response = $response;
$this->_configLoader = $configLoader;
$this->_state = $state;
$this->_filesystem = $filesystem;
}
/**
* Run application
*
* @return ResponseInterface
*/
public function launch()
{
try {
$areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
$this->_state->setAreaCode($areaCode);
$this->_objectManager->configure($this->_configLoader->load($areaCode));
$this->_response = $this->_objectManager->get('Magento\Framework\App\FrontControllerInterface')
->dispatch($this->_request);
// This event gives possibility to launch something before sending output (allow cookie setting)
$eventParams = array('request' => $this->_request, 'response' => $this->_response);
$this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
} catch (\Exception $exception) {
$message = $exception->getMessage() . "\n";
try {
if ($this->_state->getMode() == State::MODE_DEVELOPER) {
$message .= '<pre>';
$message .= $exception->getMessage() . "\n\n";
$message .= $exception->getTraceAsString();
$message .= '</pre>';
} else {
$reportData = array($exception->getMessage(), $exception->getTraceAsString());
// retrieve server data
if (isset($_SERVER)) {
if (isset($_SERVER['REQUEST_URI'])) {
$reportData['url'] = $_SERVER['REQUEST_URI'];
}
if (isset($_SERVER['SCRIPT_NAME'])) {
$reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
}
}
require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
$processor = new \Magento\Framework\Error\Processor($this->_response);
$processor->saveReport($reportData);
$this->_response = $processor->processReport();
}
} catch (\Exception $exception) {
$message .= "Unknown error happened.";
}
$this->_response->setHttpResponseCode(500);
$this->_response->setBody($message);
}
return $this->_response;
}
}