/** * @throws ExceptionSitemap * @returns SiteMapA */ public function getSiteMap() { if (SiteMapA::isValid($this->oSiteMap)) { return $this->oSiteMap; } else { throw new ExceptionSitemap('No sitemap loaded.'); } }
/** * @return string */ public function getModulePath() { $sModulePath = $this->getPath(); if (!SiteMapA::isValidMapPath($sModulePath) && SiteMapA::isValidObjectPath($sModulePath)) { $sModulePath = $this->getModuleMap()->getModulePath(); } if (!UrlParserA::hasGoodTermination($sModulePath, DIRECTORY_SEPARATOR)) { $sModulePath .= DIRECTORY_SEPARATOR; } return $sModulePath; }
public function getView() { if (!ViewA::isValid($this->oView) && !is_null($this->sViewPath)) { if (stristr(basename($this->sViewPath), '.') === false && !is_file($this->sViewPath)) { $sClassName = $this->sViewPath; } elseif (is_file($this->sViewPath)) { $sViewPath = $this->getViewPath(); try { include $sViewPath; } catch (\Exception $e) { \vsc\_e($e); } $sClassName = SiteMapA::getClassName($sViewPath); } } if (!empty($sClassName)) { $this->oView = new $sClassName(); } return $this->oView; }
public function testBasicGetClassName() { $sProcessorPath = VSC_FIXTURE_PATH . 'application/processors/ProcessorFixture.php'; $this->assertEquals('stdClass', SiteMapA::getClassName($sProcessorPath)); }
/** * * @param string $sRegex * @param string $sPath * @throws ExceptionController * @throws ExceptionSitemap * @returns ControllerMap */ public function mapController($sRegex, $sPath) { if (!$sRegex) { throw new ExceptionSitemap('An URI must be present.'); } $sKey = $sRegex; if (array_key_exists($sKey, $this->aControllerMaps)) { unset($this->aControllerMaps[$sKey]); } if (class_exists($sPath)) { // instead of a path we have a namespace $oNewMap = new ClassMap($sPath, $sKey); $oNewMap->setModuleMap($this); $oNewMap->merge($this); $this->aControllerMaps[$sKey] = $oNewMap; return $oNewMap; } else { $sPath = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $sPath); if (!SiteMapA::isValidObjectPath($sPath)) { $sPath = $this->getModulePath() . $sPath; } if (SiteMapA::isValidObjectPath($sPath)) { $oNewMap = new ControllerMap($sPath, $sKey); $oNewMap->setModuleMap($this); $oNewMap->merge($this); $this->aControllerMaps[$sKey] = $oNewMap; return $oNewMap; } else { throw new ExceptionController('Controller [' . $sPath . '] is invalid.'); } } }
public function addClassMap($sRegex, $sClassName) { return parent::addClassMap($sRegex, $sClassName); }
/** * (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; }