コード例 #1
0
 /**
  * Finds requested resource and provides it to the client
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \Exception
  */
 public function launch()
 {
     $appMode = $this->state->getMode();
     if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
         $this->response->setHttpResponseCode(404);
     } else {
         try {
             $path = $this->request->get('resource');
             $params = $this->parsePath($path);
             $this->state->setAreaCode($params['area']);
             $this->objectManager->configure($this->configLoader->load($params['area']));
             $file = $params['file'];
             unset($params['file']);
             $asset = $this->assetRepo->createAsset($file, $params);
             $this->response->setFilePath($asset->getSourceFile());
             $this->publisher->publish($asset);
         } catch (\Exception $e) {
             if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
                 throw $e;
             }
             $this->response->setHttpResponseCode(404);
         }
     }
     return $this->response;
 }
コード例 #2
0
 public function testCatchExceptionDeveloperMode()
 {
     $bootstrap = $this->getMockBuilder(Bootstrap::class)->disableOriginalConstructor()->getMock();
     $bootstrap->expects($this->once())->method('isDeveloperMode')->willReturn(true);
     $exception = new \Exception('Error: nothing works');
     $this->response->expects($this->once())->method('setHttpResponseCode')->with(404);
     $this->response->expects($this->once())->method('sendResponse');
     $this->assertTrue($this->object->catchException($bootstrap, $exception));
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function catchException(Bootstrap $bootstrap, \Exception $exception)
 {
     $this->response->setHttpResponseCode(404);
     $this->response->setHeader('Content-Type', 'text/plain');
     if ($bootstrap->isDeveloperMode()) {
         $this->response->setBody($exception->getMessage() . "\n" . $exception->getTraceAsString());
     }
     $this->response->sendResponse();
     return true;
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function catchException(Bootstrap $bootstrap, \Exception $exception)
 {
     if ($bootstrap->isDeveloperMode()) {
         $this->response->setHttpResponseCode(404);
         $this->response->setHeader('Content-Type', 'text/plain');
         $this->response->setBody($exception->getMessage() . "\n" . $exception->getTraceAsString());
         $this->response->sendResponse();
     } else {
         require $this->getFilesystem()->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/404.php');
     }
     return true;
 }
コード例 #5
0
 public function testCatchException()
 {
     $bootstrap = $this->getMock('Magento\\Framework\\App\\Bootstrap', [], [], '', false);
     $bootstrap->expects($this->at(0))->method('isDeveloperMode')->willReturn(false);
     $bootstrap->expects($this->at(1))->method('isDeveloperMode')->willReturn(true);
     $exception = new \Exception('message');
     $this->response->expects($this->exactly(2))->method('setHttpResponseCode')->with(404);
     $this->response->expects($this->exactly(2))->method('setHeader')->with('Content-Type', 'text/plain');
     $this->response->expects($this->exactly(2))->method('sendResponse');
     $this->response->expects($this->once())->method('setBody')->with($this->stringStartsWith('message'));
     $this->assertTrue($this->object->catchException($bootstrap, $exception));
     $this->assertTrue($this->object->catchException($bootstrap, $exception));
 }
コード例 #6
0
 /**
  * @param string $mode
  * @param string $requestedPath
  * @param string $expectedModule
  * @param bool $moduleExists
  * @param string $expectedFile
  * @param array $expectedParams
  *
  * @dataProvider launchDataProvider
  */
 public function testLaunch($mode, $requestedPath, $expectedModule, $moduleExists, $expectedFile, array $expectedParams)
 {
     $this->state->expects($this->once())->method('getMode')->will($this->returnValue($mode));
     $this->state->expects($this->once())->method('setAreaCode')->with('area');
     $this->configLoader->expects($this->once())->method('load')->with('area')->will($this->returnValue(array('config')));
     $this->objectManager->expects($this->once())->method('configure')->with(array('config'));
     $this->request->expects($this->once())->method('get')->with('resource')->will($this->returnValue($requestedPath));
     $this->moduleList->expects($this->any())->method('getModule')->with($expectedModule)->will($this->returnValue($moduleExists));
     $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface');
     $asset->expects($this->once())->method('getSourceFile')->will($this->returnValue('resource/file.css'));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($expectedFile, $expectedParams)->will($this->returnValue($asset));
     $this->publisher->expects($this->once())->method('publish')->with($asset);
     $this->response->expects($this->once())->method('setFilePath')->with('resource/file.css');
     $this->object->launch();
 }