/** * This method render the view. * * @throws Exception * @var $httpServerHost absolute host url. * @var $serverHost absolute host path. * @var $ABSOLUTE_URL absolute host url. * @var $SERVER_HOST absolute host path. * @var $LEAD_FILENAME leading filename ex: index.php. * */ public function render() { try { if (!is_null($this->_viewFilePath) && file_exists($this->_viewFilePath)) { if (!is_null($this->_variables)) { foreach ($this->_variables as $name => $value) { if ($value instanceof UIComponent || $value instanceof JsUIComponentInterface) { $htmlValue = $value->render(); $newHtmlValue = $this->_languageService->replaceWordByKey($htmlValue); ${$name} = $newHtmlValue; $this->hasAnyScript($newHtmlValue); } else { ${$name} = $value; } } } $httpServerHost = PathService::getAbsoluteHostURL(); $serverHost = PathService::getAbsoluteHostPath(); $ABSOLUTE_URL = PathService::getAbsoluteHostURL(); $SERVER_HOST = PathService::getAbsoluteHostPath(); $LEAD_FILENAME = Config::getInstance()->getLeadFileName(); $viewContent = file_get_contents($this->_viewFilePath); $this->hasAnyScript($viewContent); //hasScript check if there is a need for javascript library to be added in //If there is no javascript UI component, but setScript == true, we still //add plugins. Otherwise, we simply do not add any libraries. if ($this->_hasScript) { //add plugins $viewContent = $this->addPluginLib($viewContent); } //$viewContent = $this->_languageService->replaceWordByKey($viewContent); //Check if inserting doctype at the beginning of the view content if (!$this->_inLayout) { if (!$this->_noDoctype) { if (is_null($this->_doctype)) { $this->setDoctype(); } $viewContent = $this->_doctype . $viewContent; } } $fp = fopen("airy.view://view_content", "r+"); fwrite($fp, $viewContent); fclose($fp); if (!$this->_inLayout) { //use ob_start to push all include files into a buffer //and then call the callback function replaceLanguageWords //only use stream writter cannot fulfill this ob_start(array($this, 'replaceLanguageWords')); include "airy.view://view_content"; ob_end_flush(); } else { $this->_viewScripts = file_get_contents("airy.view://view_content"); return $this->_viewScripts; } } else { throw new Exception("No View File {$this->_viewFilePath} Existed!"); } } catch (Exception $e) { echo 'Exception: ', $e->getMessage(), "\n"; } }