|
5 | 5 | */
|
6 | 6 | namespace Magento\Framework\App;
|
7 | 7 |
|
| 8 | +use Magento\Framework\App\Filesystem\DirectoryList; |
8 | 9 | use Magento\Framework\ObjectManager\ConfigLoaderInterface;
|
| 10 | +use Magento\Framework\Filesystem; |
9 | 11 |
|
10 | 12 | /**
|
11 | 13 | * Entry point for retrieving static resources like JS, CSS, images by requested public path
|
|
14 | 16 | */
|
15 | 17 | class StaticResource implements \Magento\Framework\AppInterface
|
16 | 18 | {
|
17 |
| - /** |
18 |
| - * @var State |
19 |
| - */ |
| 19 | + /** @var State */ |
20 | 20 | private $state;
|
21 | 21 |
|
22 |
| - /** |
23 |
| - * @var \Magento\Framework\App\Response\FileInterface |
24 |
| - */ |
| 22 | + /** @var \Magento\Framework\App\Response\FileInterface */ |
25 | 23 | private $response;
|
26 | 24 |
|
27 |
| - /** |
28 |
| - * @var Request\Http |
29 |
| - */ |
| 25 | + /** @var Request\Http */ |
30 | 26 | private $request;
|
31 | 27 |
|
32 |
| - /** |
33 |
| - * @var View\Asset\Publisher |
34 |
| - */ |
| 28 | + /** @var View\Asset\Publisher */ |
35 | 29 | private $publisher;
|
36 | 30 |
|
37 |
| - /** |
38 |
| - * @var \Magento\Framework\View\Asset\Repository |
39 |
| - */ |
| 31 | + /** @var \Magento\Framework\View\Asset\Repository */ |
40 | 32 | private $assetRepo;
|
41 | 33 |
|
42 |
| - /** |
43 |
| - * @var \Magento\Framework\Module\ModuleList |
44 |
| - */ |
| 34 | + /** @var \Magento\Framework\Module\ModuleList */ |
45 | 35 | private $moduleList;
|
46 | 36 |
|
47 |
| - /** |
48 |
| - * @var \Magento\Framework\ObjectManagerInterface |
49 |
| - */ |
| 37 | + /** @var \Magento\Framework\ObjectManagerInterface */ |
50 | 38 | private $objectManager;
|
51 | 39 |
|
52 |
| - /** |
53 |
| - * @var ConfigLoaderInterface |
54 |
| - */ |
| 40 | + /** @var ConfigLoaderInterface */ |
55 | 41 | private $configLoader;
|
56 | 42 |
|
| 43 | + /** @var Filesystem */ |
| 44 | + private $filesystem; |
| 45 | + |
57 | 46 | /**
|
58 | 47 | * @param State $state
|
59 | 48 | * @param Response\FileInterface $response
|
@@ -116,12 +105,14 @@ public function launch()
|
116 | 105 | */
|
117 | 106 | public function catchException(Bootstrap $bootstrap, \Exception $exception)
|
118 | 107 | {
|
119 |
| - $this->response->setHttpResponseCode(404); |
120 |
| - $this->response->setHeader('Content-Type', 'text/plain'); |
121 | 108 | if ($bootstrap->isDeveloperMode()) {
|
| 109 | + $this->response->setHttpResponseCode(404); |
| 110 | + $this->response->setHeader('Content-Type', 'text/plain'); |
122 | 111 | $this->response->setBody($exception->getMessage() . "\n" . $exception->getTraceAsString());
|
| 112 | + $this->response->sendResponse(); |
| 113 | + } else { |
| 114 | + require $this->getFilesystem()->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/404.php'); |
123 | 115 | }
|
124 |
| - $this->response->sendResponse(); |
125 | 116 | return true;
|
126 | 117 | }
|
127 | 118 |
|
@@ -156,4 +147,18 @@ protected function parsePath($path)
|
156 | 147 | $result['file'] = $parts[5];
|
157 | 148 | return $result;
|
158 | 149 | }
|
| 150 | + |
| 151 | + /** |
| 152 | + * Lazyload filesystem driver |
| 153 | + * |
| 154 | + * @deprecated |
| 155 | + * @return Filesystem |
| 156 | + */ |
| 157 | + private function getFilesystem() |
| 158 | + { |
| 159 | + if (!$this->filesystem) { |
| 160 | + $this->filesystem = $this->objectManager->get(Filesystem::class); |
| 161 | + } |
| 162 | + return $this->filesystem; |
| 163 | + } |
159 | 164 | }
|
0 commit comments