public function run(&$params) { if (!defined('BUILD_LITE_FILE')) { return; } $litefile = C('RUNTIME_LITE_FILE', null, RUNTIME_PATH . 'lite.php'); if (is_file($litefile)) { return; } $defs = get_defined_constants(TRUE); $content = 'namespace {$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; if (MEMORY_LIMIT_ON) { $content .= '$GLOBALS[\'_startUseMems\'] = memory_get_usage();'; } // 生成数组定义 unset($defs['user']['BUILD_LITE_FILE']); $content .= $this->buildArrayDefine($defs['user']) . '}'; // 读取编译列表文件 $filelist = is_file(CONF_PATH . 'lite.php') ? include CONF_PATH . 'lite.php' : array(ANY_PATH . 'Common/functions.php', COMMON_PATH . 'Common/function.php', CORE_PATH . 'Any' . EXT, CORE_PATH . 'Hook' . EXT, CORE_PATH . 'App' . EXT, CORE_PATH . 'Dispatcher' . EXT, CORE_PATH . 'Log' . EXT, CORE_PATH . 'Log/Driver/File' . EXT, CORE_PATH . 'Route' . EXT, CORE_PATH . 'Controller' . EXT, CORE_PATH . 'View' . EXT, CORE_PATH . 'Storage' . EXT, CORE_PATH . 'Storage/Driver/File' . EXT, CORE_PATH . 'Exception' . EXT, BEHAVIOR_PATH . 'ParseTemplateBehavior' . EXT, BEHAVIOR_PATH . 'ContentReplaceBehavior' . EXT); // 编译文件 foreach ($filelist as $file) { if (is_file($file)) { $content .= compile($file); } } // 处理Any类的start方法 $content = preg_replace('/\\$runtimefile = RUNTIME_PATH(.+?)(if\\(APP_STATUS)/', '\\2', $content, 1); $content .= "\nnamespace { Any\\Any::addMap(" . var_export(\Any\Any::getMap(), true) . ");"; $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Any\\Hook::import(' . var_export(\Any\Hook::get(), true) . ');Any\\Any::start();}'; // 生成运行Lite文件 file_put_contents($litefile, strip_whitespace('<?php ' . $content)); }
/** * 检查静态HTML文件是否有效 * 如果无效需要重新更新 * @access public * @param string $cacheFile 静态文件名 * @param integer $cacheTime 缓存有效期 * @return boolean */ public static function checkHTMLCache($cacheFile = '', $cacheTime = '') { if (!is_file($cacheFile) && 'sae' != APP_MODE) { return false; } elseif (filemtime(\Any\Any::instance('Any\\View')->parseTemplate()) > Storage::get($cacheFile, 'mtime', 'html')) { // 模板文件如果更新静态文件需要更新 return false; } elseif (!is_numeric($cacheTime) && function_exists($cacheTime)) { return $cacheTime($cacheFile); } elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile, 'mtime', 'html') + $cacheTime) { // 文件是否在有效期 return false; } //静态文件有效 return true; }
/** * 架构函数 * @access public */ public function __construct() { $this->tagLib = strtolower(substr(get_class($this), 6)); $this->tpl = \Any\Any::instance('Any\\Template'); }
/** * TagLib库解析 * @access public * @param string $tagLib 要解析的标签库 * @param string $content 要解析的模板内容 * @param boolean $hide 是否隐藏标签库前缀 * @return string */ public function parseTagLib($tagLib, &$content, $hide = false) { $begin = $this->config['taglib_begin']; $end = $this->config['taglib_end']; if (strpos($tagLib, '\\')) { // 支持指定标签库的命名空间 $className = $tagLib; $tagLib = substr($tagLib, strrpos($tagLib, '\\') + 1); } else { $className = 'Any\\Template\\TagLib\\' . ucwords($tagLib); } $tLib = \Any\Any::instance($className); $that = $this; foreach ($tLib->getTags() as $name => $val) { $tags = array($name); if (isset($val['alias'])) { // 别名设置 $tags = explode(',', $val['alias']); $tags[] = $name; } $level = isset($val['level']) ? $val['level'] : 1; $closeTag = isset($val['close']) ? $val['close'] : true; foreach ($tags as $tag) { $parseTag = !$hide ? $tagLib . ':' . $tag : $tag; // 实际要解析的标签名称 if (!method_exists($tLib, '_' . $tag)) { // 别名可以无需定义解析方法 $tag = $name; } $n1 = empty($val['attr']) ? '(\\s*?)' : '\\s([^' . $end . ']*)'; $this->tempVar = array($tagLib, $tag); if (!$closeTag) { $patterns = '/' . $begin . $parseTag . $n1 . '\\/(\\s*?)' . $end . '/is'; $content = preg_replace_callback($patterns, function ($matches) use($tLib, $tag, $that) { return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]); }, $content); } else { $patterns = '/' . $begin . $parseTag . $n1 . $end . '(.*?)' . $begin . '\\/' . $parseTag . '(\\s*?)' . $end . '/is'; for ($i = 0; $i < $level; $i++) { $content = preg_replace_callback($patterns, function ($matches) use($tLib, $tag, $that) { return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]); }, $content); } } } } }