/** * 加载主模板并缓存 * @access public * @param string $tmplTemplateFile 模板文件 * @param string $prefix 模板标识前缀 * @return string * @throws ThinkExecption */ public function loadTemplate($tmplTemplateFile, $prefix = '') { if (is_file($tmplTemplateFile)) { $this->templateFile = $tmplTemplateFile; // 读取模板文件内容 $tmplContent = file_get_contents($tmplTemplateFile); } else { $tmplContent = $tmplTemplateFile; } // 根据模版文件名定位缓存文件 $tmplCacheFile = $this->config['cache_path'] . $prefix . md5($tmplTemplateFile) . $this->config['cache_suffix']; // 判断是否启用布局 if (C('LAYOUT_ON')) { if (false !== strpos($tmplContent, '{__NOLAYOUT__}')) { // 可以单独定义不使用布局 $tmplContent = str_replace('{__NOLAYOUT__}', '', $tmplContent); } else { // 替换布局的主体内容 $layoutFile = THEME_PATH . C('LAYOUT_NAME') . $this->config['template_suffix']; $tmplContent = str_replace($this->config['layout_item'], $tmplContent, file_get_contents($layoutFile)); } } // 编译模板内容 $tmplContent = $this->compiler($tmplContent); //[cluster] 去掉检测模板目录 //[cluster] 重写Cache文件 if (false === ThinkFS::set($tmplCacheFile, trim($tmplContent))) { throw_exception(L('_CACHE_WRITE_ERROR_') . ':' . $tmplCacheFile); } return $tmplCacheFile; }
function build_runtime_cache($append = '') { // 生成编译文件 $defs = get_defined_constants(TRUE); $content = '$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; if (defined('RUNTIME_DEF_FILE')) { // 编译后的常量文件外部引入 file_put_contents(RUNTIME_DEF_FILE, '<?php ' . array_define($defs['user'])); $content .= 'require \'' . RUNTIME_DEF_FILE . '\';'; } else { $content .= array_define($defs['user']); } $content .= 'set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH);'; // 读取核心编译文件列表 $list = array(THINK_PATH . 'Common/common.php', CLUSTER_PATH . 'Lib/Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php'); //[cluster] 判断加载IO.php文件 $content .= 'if(!function_exists(\'runtime_set\')){' . compile(IO_PATH) . '}'; //[cluster] 判断加载ThinkFS文件 $content .= 'if(!class_exists(\'ThinkFS\')){' . compile(CLUSTER_PATH . 'Lib/Core/ThinkFS.class.php') . '}'; foreach ($list as $file) { $content .= compile($file); } // 系统行为扩展文件统一编译 $content .= build_tags_cache(); $alias = (include CLUSTER_PATH . 'Conf/alias.php'); $content .= 'alias_import(' . var_export($alias, true) . ');'; // 编译框架默认语言包和配置参数 $content .= $append . "\nL(" . var_export(L(), true) . ");C(" . var_export(C(), true) . ');G(\'loadTime\');Think::Start();'; //[cluster] 生成核心缓存 ThinkFS::set(RUNTIME_FILE, strip_whitespace('<?php ' . str_replace("defined('THINK_PATH') or exit();", ' ', $content))); }