/** * compiles specified tpl file and execution result in Context into resultant content * @param string $tpl_path path of the directory containing target template file * @param string $tpl_filename target template file's name * @param string $tpl_file if specified use it as template file's full path * @return string Returns compiled result in case of success, NULL otherwise */ public function compile($tpl_path, $tpl_filename, $tpl_file = '') { // store the starting time for debug information $start = microtime(true); // initiation $this->init($tpl_path, $tpl_filename, $tpl_file); // if target file does not exist exit if (!$this->file || !file_exists($this->file)) { $error_message = "Template not found: {$tpl_path}{$tpl_filename}" . ($tpl_file ? " ({$tpl_file})" : ''); trigger_error($error_message, \E_USER_WARNING); return escape($error_message); } // for backward compatibility if (is_null(self::$rootTpl)) { self::$rootTpl = $this->file; } $latest_mtime = max(filemtime($this->file), $this->handler_mtime); // make compiled file if (!file_exists($this->compiled_file) || filemtime($this->compiled_file) < $latest_mtime) { $buff = $this->parse(); if (Rhymix\Framework\Storage::write($this->compiled_file, $buff) === false) { $tmpfilename = tempnam(sys_get_temp_dir(), 'rx-compiled'); if ($tmpfilename === false || Rhymix\Framework\Storage::write($tmpfilename, $buff) === false) { return 'Fatal Error : Cannot create temporary file. Please check permissions.'; } $this->compiled_file = $tmpfilename; } } Rhymix\Framework\Debug::addFilenameAlias($this->file, $this->compiled_file); $output = $this->_fetch($this->compiled_file); // delete tmpfile if (isset($tmpfilename)) { Rhymix\Framework\Storage::delete($tmpfilename); } if ($__templatehandler_root_tpl == $this->file) { $__templatehandler_root_tpl = null; } // store the ending time for debug information $GLOBALS['__template_elapsed__'] += microtime(true) - $start; return $output; }
/** * compiles specified tpl file and execution result in Context into resultant content * @param string $tpl_path path of the directory containing target template file * @param string $tpl_filename target template file's name * @param string $tpl_file if specified use it as template file's full path * @return string Returns compiled result in case of success, NULL otherwise */ public function compile($tpl_path, $tpl_filename, $tpl_file = '') { $buff = false; // store the starting time for debug information if (__DEBUG__ == 3) { $start = getMicroTime(); } // initiation $this->init($tpl_path, $tpl_filename, $tpl_file); // if target file does not exist exit if (!$this->file || !file_exists($this->file)) { return "Err : '{$this->file}' template file does not exists."; } // for backward compatibility if (is_null(self::$rootTpl)) { self::$rootTpl = $this->file; } $source_template_mtime = filemtime($this->file); $latest_mtime = $source_template_mtime > $this->handler_mtime ? $source_template_mtime : $this->handler_mtime; // cache control $oCacheHandler = CacheHandler::getInstance('template'); // get cached buff if ($oCacheHandler->isSupport()) { $cache_key = 'template:' . $this->file; $buff = $oCacheHandler->get($cache_key, $latest_mtime); } else { if (is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) { $buff = 'file://' . $this->compiled_file; } } if ($buff === FALSE) { $buff = $this->parse(); if ($oCacheHandler->isSupport()) { $oCacheHandler->put($cache_key, $buff); } else { FileHandler::writeFile($this->compiled_file, $buff); } } $output = $this->_fetch($buff); if ($__templatehandler_root_tpl == $this->file) { $__templatehandler_root_tpl = null; } // store the ending time for debug information if (__DEBUG__ == 3) { $GLOBALS['__template_elapsed__'] += getMicroTime() - $start; } return $output; }