Пример #1
0
 public function testBasic__construct()
 {
     $e = new Exception('test');
     $o = new ErrorProcessor($e);
     $this->assertInstanceOf(\Exception::class, $o->getModel()->getException());
     $this->assertInstanceOf(ErrorMap::class, $o->getMap());
     $this->assertEquals('templates', basename($o->getMap()->getTemplatePath()));
     $this->assertEquals('error.tpl.php', $o->getMap()->getTemplate());
 }
Пример #2
0
 /**
  * @param \Exception $e
  * @param HttpRequestA $oRequest
  * @return HttpResponseA
  * @throws ExceptionPath
  * @throws ExceptionResponse
  */
 public function getErrorResponse(\Exception $e, $oRequest = null)
 {
     $oResponse = vsc::getEnv()->getHttpResponse();
     $oProcessor = new ErrorProcessor($e);
     /* @var ControllerMap $oMyMap */
     $oMyMap = $this->getMap();
     $oMyMap->setMainTemplatePath(VSC_RES_PATH . 'templates');
     $oMyMap->setMainTemplate('main.php');
     if (!HttpRequestA::isValid($oRequest)) {
         $oRequest = vsc::getEnv()->getHttpRequest();
     }
     /** @var ErrorModel $oModel */
     $oModel = $oProcessor->handleRequest($oRequest);
     $iCode = $oModel->getHttpStatus();
     if (HttpResponseType::isValidStatus($iCode)) {
         $oResponse->setStatus($iCode);
     } else {
         $oResponse->setStatus(500);
     }
     // we didn't set any special view
     // this means that the developer needs to provide his own views
     $oView = $this->getView();
     /* @var ProcessorMap $oMap */
     $oMap = $oProcessor->getMap();
     $oMap->merge($oMyMap);
     $oProcessorResponse = $oMap->getResponse();
     if (HttpResponseA::isValid($oProcessorResponse)) {
         $oResponse = $oProcessorResponse;
     }
     // setting the processor map
     $oView->setMap($oMap);
     if (ControllerMap::isValid($oMyMap)) {
         $oView->setMainTemplate($oMyMap->getMainTemplatePath() . DIRECTORY_SEPARATOR . $oView->getViewFolder() . DIRECTORY_SEPARATOR . $oMyMap->getMainTemplate());
     }
     $oView->setModel($oModel);
     $oResponse->setView($oView);
     $aHeaders = $oMap->getHeaders();
     if (count($aHeaders) > 0) {
         foreach ($aHeaders as $sName => $sHeader) {
             $oResponse->addHeader($sName, $sHeader);
         }
     }
     return $oResponse;
 }