Example #1
0
 public function testBasicHandleRequest()
 {
     $e = new ExceptionResponseError('test', HttpResponseType::NO_CONTENT);
     $o = new ErrorProcessor($e);
     $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest());
     $this->assertInstanceOf(ErrorModel::class, $oModel);
     $this->assertInstanceOf(ExceptionResponseError::class, $oModel->getException());
     $this->assertEquals(HttpResponseType::NO_CONTENT, $oModel->getException()->getErrorCode());
 }
Example #2
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());
 }
Example #3
0
 public function testGetExceptionResponseErrorVariousErrorCodes()
 {
     $oResponseTypeMirror = new \ReflectionClass(HttpResponseType::class);
     $aStatusProperties = $oResponseTypeMirror->getStaticProperties();
     $aStatuses = $aStatusProperties['aStatusList'];
     foreach ($aStatuses as $iStatus => $sResponseStatus) {
         $e = new ExceptionResponseError('test', $iStatus);
         $o = new ErrorProcessor($e);
         $this->assertEquals($iStatus, $o->getErrorCode());
     }
 }
Example #4
0
 public function testLoadSiteMap()
 {
     $Exception = new ExceptionError('test', 123);
     $o = new ErrorProcessor($Exception);
     $oMap = new ClassMap(ErrorProcessor::class, '.*');
     $o->setMap($oMap);
     $sFixturePath = VSC_FIXTURE_PATH . 'config' . DIRECTORY_SEPARATOR;
     $o = new RwDispatcher();
     $o->loadSiteMap($sFixturePath . 'map.php');
     $this->assertInstanceOf(SiteMapA::class, $o->getSiteMap());
 }
Example #5
0
 public function testBasicSetException()
 {
     $Exception = new ExceptionError('test', 123);
     $o = new ErrorProcessor($Exception);
     $oMap = new ClassMap(ErrorProcessor::class, '.*');
     $sMessage = uniqid('MESSAGE:');
     $sCode = uniqid('CODE:');
     $iError = HttpResponseType::CLIENT_ERROR;
     $Exception = new ExceptionResponseError($sMessage, $iError);
     $o->setException($Exception);
     $this->assertInstanceOf(\vsc\domain\models\ErrorModel::class, $o->getModel());
     $this->assertEquals($sMessage, $o->getModel()->getMessage());
     $this->assertEquals($iError, $o->getModel()->getHttpStatus());
 }
Example #6
0
 public function testGetException()
 {
     $Exception = new ExceptionError('test', 123);
     $o = new ErrorProcessor($Exception);
     $sMessage = uniqid('MESSAGE:');
     $iError = HttpResponseType::CLIENT_ERROR;
     $o->setException(new ExceptionResponseError($sMessage, $iError));
     $oModel = $o->getModel();
     $this->assertInstanceOf(\vsc\domain\models\ErrorModel::class, $oModel);
     $Exception = $oModel->getException();
     $this->assertInstanceOf(ExceptionResponseError::class, $Exception);
     $this->assertInstanceOf(\vsc\presentation\responses\ExceptionResponse::class, $Exception);
     $this->assertInstanceOf(\vsc\presentation\ExceptionPresentation::class, $Exception);
 }
Example #7
0
 public function handleRequest(HttpRequestA $oHttpRequest)
 {
     $o404 = vsc::getEnv()->getHttpResponse();
     $o404->setStatus(404);
     $this->getMap()->setResponse($o404);
     return parent::handleRequest($oHttpRequest);
 }
Example #8
0
 public function testUseless()
 {
     $e = new \Exception('asd');
     $o = new ErrorProcessor($e);
     $this->assertNull($o->init());
 }
Example #9
0
 /**
  * (non-PHPdoc)
  * @see lib/presentation/dispatchers/vscDispatcherA#getProcessController()
  * @throws ExceptionSitemap
  * @throws ExceptionResponseError
  * @returns ProcessorA
  */
 public function getProcessController()
 {
     if (!ProcessorA::isValid($this->oProcessor)) {
         $oProcessorMap = $this->getCurrentProcessorMap();
         if (!ProcessorMap::isValid($oProcessorMap) && !ClassMap::isValid($oProcessorMap)) {
             // this mainly means nothing was matched to our url, or no mappings exist, so we're falling back to 404
             $oProcessorMap = new ProcessorMap(NotFoundProcessor::class, '.*');
             $oProcessorMap->setTemplatePath(VSC_RES_PATH . 'templates');
             $oProcessorMap->setTemplate('404.php');
         }
         $sPath = $oProcessorMap->getPath();
         try {
             $sProcessorName = null;
             if ($this->getSiteMap()->isValidObjectPath($sPath) || stristr(basename($sPath), '.') === false && !is_file($sPath)) {
                 // dirty import of the module folder and important subfolders - @FIXME
                 $sModuleName = $oProcessorMap->getModuleName();
                 if (stristr(basename($sPath), '.') === false && !is_file($sPath)) {
                     // namespaced class name
                     $sProcessorName = $sPath;
                 } elseif (is_file($sPath)) {
                     try {
                         include $sPath;
                     } catch (\Exception $e) {
                         \vsc\_e($e);
                     }
                     $sProcessorName = SiteMapA::getClassName($sPath);
                 }
                 try {
                     if (class_exists($sProcessorName)) {
                         $this->oProcessor = new $sProcessorName();
                     } else {
                         $this->oProcessor = new NotFoundProcessor();
                     }
                 } catch (\Exception $e) {
                     $this->oProcessor = new ErrorProcessor($e);
                 }
             } elseif ($this->getSiteMap()->isValidStaticPath($sPath)) {
                 // static stuff
                 $this->oProcessor = new StaticFileProcessor();
                 $this->oProcessor->setFilePath($sPath);
             }
             /*else {
             			$this->oProcessor = new NotFoundProcessor();
             		}*/
             if (ProcessorA::isValid($this->oProcessor)) {
                 if (!(ErrorProcessor::isValid($this->oProcessor) && MappingA::isValid($this->oProcessor->getMap()))) {
                     // @TODO: this should be a MappingA->merge() when the processor already has a map
                     $this->oProcessor->setMap($oProcessorMap);
                 }
                 // setting the variables defined in the processor into the tainted variables
                 /** @var RwHttpRequest $oRawRequest */
                 $oRawRequest = $this->getRequest();
                 if (RwHttpRequest::isValid($oRawRequest)) {
                     $oRawRequest->setTaintedVars($this->oProcessor->getLocalVars());
                     // FIXME!!!
                 }
             } else {
                 //					\vsc\d($sPath, $this->oProcessor);
                 //					\vsc\d($this->oProcessor);
                 // broken URL
                 throw new ExceptionResponseError('Broken URL', 400);
             }
         } catch (ExceptionResponseRedirect $e) {
             // get the response
             $oResponse = vsc::getEnv()->getHttpResponse();
             $oResponse->setLocation($e->getLocation());
             ob_end_flush();
             $oResponse->outputHeaders();
         }
     }
     return $this->oProcessor;
 }
Example #10
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;
 }