Example #1
0
 public function __construct($sPath, $sRegex)
 {
     $sPath = realpath(dirname($sPath));
     if (basename($sPath) == 'config') {
         $sPath = substr($sPath, 0, -7);
     }
     $sPath .= DIRECTORY_SEPARATOR;
     $this->setTemplatePath(VSC_RES_PATH . 'templates' . DIRECTORY_SEPARATOR);
     parent::__construct($sPath, $sRegex);
 }
Example #2
0
 public function __construct($sPath = null, $sRegex = null)
 {
     if (is_null($sPath)) {
         $sPath = __FILE__;
     }
     if (is_null($sRegex)) {
         $sRegex = '.*';
     }
     parent::__construct($sPath, $sRegex);
 }
Example #3
0
 public function __construct($sPath = null, $sRegex = null)
 {
     if (is_null($sPath)) {
         $sPath = __FILE__;
     }
     if (is_null($sRegex)) {
         $sRegex = '.*';
     }
     parent::addHeader('Accept', 'application/json');
     parent::__construct($sPath, $sRegex);
 }
Example #4
0
 /**
  * @return MappingA|null
  */
 public function getParentModuleMap()
 {
     if (MappingA::isValid($this->oCurrentModuleMap)) {
         $oParentModule = $this->oCurrentModuleMap->getModuleMap();
         if (ModuleMap::isValid($oParentModule)) {
             return $oParentModule;
         }
     }
     // return a default root node
     return new ModuleMap(VSC_RES_PATH . 'config/map.php', '');
 }
Example #5
0
 public function mergeResources($oMap)
 {
     parent::mergeResources($oMap);
 }
Example #6
0
 /**
  * @param string $sPath
  * @return string
  * @throws ExceptionSitemap
  */
 public function getValidPath($sPath)
 {
     return parent::getValidPath($sPath);
 }
Example #7
0
 /**
  * @returns ModuleMap
  */
 public function getModuleMap()
 {
     if (!MappingA::isValid($this->oParentMap)) {
         $this->oParentMap = new ModuleMap(VSC_RES_PATH . 'config/map.php', '');
     }
     return $this->oParentMap;
 }
Example #8
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 #9
0
 public function mergePaths($oMap)
 {
     return parent::mergePaths($oMap);
 }
Example #10
0
 /**
  *
  * @see ProcessorI::delegateRequest()
  * @param HttpRequestA $oHttpRequest
  * @param ProcessorA $oNewProcessor
  * @param HttpResponseA $oResponse
  * @returns ModelA
  */
 public function delegateRequest(HttpRequestA $oHttpRequest, ProcessorA $oNewProcessor, HttpResponseA $oResponse = null)
 {
     $oDispatcher = vsc::getEnv()->getDispatcher();
     /** @var ProcessorMap $oMap */
     $oMap = $oDispatcher->getSiteMap()->findProcessorMap($oNewProcessor);
     if (MappingA::isValid($oMap)) {
         $oNewProcessor->setMap($oMap);
         $oNewProcessor->init();
         /* @var RwDispatcher $oDispatcher */
         $oMap->merge($this->getMap());
         if (HttpResponse::isValid($oResponse)) {
             $oMap->setResponse($oResponse);
         }
         $this->setMap($oMap);
     }
     $oNewProcessor->setLocalVars($this->getLocalVars(), true);
     return $oNewProcessor->handleRequest($oHttpRequest);
 }
Example #11
0
 /**
  * @throws ExceptionView
  * @returns ProcessorMap
  */
 public function getMap()
 {
     if (MappingA::isValid($this->oCurrentMap)) {
         return $this->oCurrentMap;
     } else {
         throw new ExceptionView('Make sure the current map is correctly set.');
     }
 }
Example #12
0
 /**
  * @param HttpRequestA $oRequest
  * @param ProcessorA $oProcessor
  * @throws ExceptionPath
  * @throws ExceptionResponse
  * @throws ExceptionView
  * @returns HttpResponseA
  */
 public function getResponse(HttpRequestA $oRequest, $oProcessor = null)
 {
     $oResponse = vsc::getEnv()->getHttpResponse();
     $oModel = null;
     /* @var ControllerMap $oMyMap */
     $oMyMap = $this->getMap();
     if (ProcessorA::isValid($oProcessor)) {
         try {
             $oProcessor->init();
             $oModel = $oProcessor->handleRequest($oRequest);
         } catch (ExceptionResponseRedirect $e) {
             $oResponse->setStatus($e->getRedirectCode());
             $oResponse->setLocation($e->getLocation());
             return $oResponse;
         } catch (\Exception $e) {
             // we had error in the controller
             // @todo make more error processors
             return $this->getErrorResponse($e, $oRequest);
         }
     }
     if ($oResponse->getStatus() == 0) {
         $oResponse->setStatus(HttpResponseType::OK);
     }
     // we didn't set any special view
     // this means that the developer needs to provide his own views
     $oView = $this->getView();
     $oMap = null;
     if (ProcessorA::isValid($oProcessor)) {
         /* @var ProcessorMap $oMap */
         $oMap = $oProcessor->getMap();
         if (MappingA::isValid($oMap)) {
             if (MappingA::isValid($oMyMap)) {
                 $oMap->merge($oMyMap);
             }
             $oProcessorResponse = $oMap->getResponse();
             if (HttpResponseA::isValid($oProcessorResponse)) {
                 $oResponse = $oProcessorResponse;
             }
         }
         // setting the processor map
         $oView->setMap($oMap);
     }
     try {
         if ((ProcessorMap::isValid($oMap) || ClassMap::isValid($oMap)) && !$oMap->isStatic() && !$oMyMap->isStatic() && (ControllerMap::isValid($oMyMap) || ClassMap::isValid($oMyMap))) {
             $oView->setMainTemplate($oMyMap->getMainTemplatePath() . $oView->getViewFolder() . DIRECTORY_SEPARATOR . $oMyMap->getMainTemplate());
         }
     } catch (ExceptionPath $e) {
         // fallback to html5
         // @todo verify main template path and main template exist
         $oView->setMainTemplate($oMyMap->getMainTemplatePath() . DIRECTORY_SEPARATOR . 'html5' . DIRECTORY_SEPARATOR . $oMyMap->getMainTemplate());
     }
     if (!ModelA::isValid($oModel)) {
         $oModel = new EmptyModel();
         if (!ProcessorMap::isValid($oMap) || $oMap->getTitle() == '') {
             $oModel->setPageTitle('Warning');
         }
         $oModel->setPageContent('Warning: the processor didn\'t return a valid model. This is probably an error');
     }
     $oView->setModel($oModel);
     $oResponse->setView($oView);
     if (MappingA::isValid($oMap)) {
         $aHeaders = $oMap->getHeaders();
         if (count($aHeaders) > 0) {
             foreach ($aHeaders as $sName => $sHeader) {
                 $oResponse->addHeader($sName, $sHeader);
             }
         }
         $iProcessorSetStatus = $oMap->getResponseStatus();
         if (HttpResponseType::isValidStatus($iProcessorSetStatus)) {
             $oResponse->setStatus($iProcessorSetStatus);
         }
     }
     return $oResponse;
 }