public static function include_file($_filename, $_vars = null) { self::$current_include_file = $_filename; if (!is_null($_vars)) { extract($_vars, EXTR_OVERWRITE); } $_content = isset(self::$_contents[$_filename]) ? self::$_contents[$_filename] : self::get_value($_filename, 'content'); //eval时要用@屏蔽报错才能自己接管报错,接管函数self::error。 if (@eval(' ?>' . $_content) === false) { self::error(); } self::$current_include_file = null; unset(self::$_contents[$_filename]); return true; }
// +---------------------------------------------------------------------- // | Author: luofei614 <*****@*****.**> // +---------------------------------------------------------------------- // ThinkPHP 入口文件 //[cluster] 定义路径常量 defined('CLUSTER_PATH') or define('CLUSTER_PATH', ENGINE_PATH . 'Cluster/'); //[cluster] 提前系统目录定义 defined('IO_NAME') or define('IO_NAME', 'auto'); defined('IO_PATH') or define('IO_PATH', APP_PATH . 'IO/' . IO_NAME . '.php'); //[cluster] 建立默认应用 if (!file_exists(IO_PATH)) { require CLUSTER_PATH . 'build_first_app.php'; } require IO_PATH; //[cluster] 记录开始运行时间 移动到加载IO文件之后 $GLOBALS['_beginTime'] = microtime(TRUE); //[cluster] 定义加载IO配置 defined('IO_TRUE_NAME') or define('IO_TRUE_NAME', IO_NAME); require CLUSTER_PATH . 'Lib/Core/ThinkFS.class.php'; defined('RUNTIME_PATH') or define('RUNTIME_PATH', APP_PATH . 'Runtime/'); defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式 $runtime = defined('MODE_NAME') ? '~' . strtolower(MODE_NAME) . '_runtime.php' : '~runtime.php'; defined('RUNTIME_FILE') or define('RUNTIME_FILE', RUNTIME_PATH . $runtime); if (!APP_DEBUG && ThinkFS::file_exists(RUNTIME_FILE)) { //[cluster] 部署模式直接载入运行缓存 ThinkFS::include_file(RUNTIME_FILE); } else { //[cluster] 加载运行时文件 require CLUSTER_PATH . 'Common/runtime.php'; }
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))); }
/** * 加载主模板并缓存 * @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; }
protected function checkContentCache($tmplContent, $prefix = '') { return ThinkFS::file_exists(C('CACHE_PATH') . $prefix . md5($tmplContent) . C('TMPL_CACHFILE_SUFFIX')); }