示例#1
0
文件: vsc.php 项目: bogdananton/vsc
 /**
  * @param HttpResponseA $oResponse
  */
 public function setHttpResponse(HttpResponseA $oResponse)
 {
     if (HttpResponseA::isValid($oResponse) && get_class($this->oResponse) != get_class($oResponse)) {
         $this->oResponse = $oResponse;
     }
 }
示例#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;
 }