From 45ca16e8b7bd4cb3f4e4c7bf9e766d9e722f18ff Mon Sep 17 00:00:00 2001 From: huangdijia Date: Wed, 16 Mar 2016 13:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=962=E5=A4=84=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 60 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 45021310..65be4ba9 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -221,15 +221,18 @@ class Template */ public function layout($name) { - if (false !== $name) { - $this->config['layout_on'] = true; - if (is_string($name)) { - $this->config['layout_name'] = $name; - } - } else { + if (false === $name) { // 关闭布局 $this->config['layout_on'] = false; + return $this; } + // 开启布局 + $this->config['layout_on'] = true; + // 名称必须为字符串 + if (is_string($name)) { + $this->config['layout_name'] = $name; + } + return $this; } /** @@ -241,25 +244,36 @@ class Template */ private function checkCache($cacheFile) { - if ($this->config['tpl_cache'] && is_file($cacheFile) && $handle = @fopen($cacheFile, "r")) { - // 读取第一行 - preg_match('/\/\*(.+?)\*\//', fgets($handle), $matches); - if (isset($matches[1])) { - $includeFile = unserialize($matches[1]); - if (is_array($includeFile)) { - // 检查模板文件是否有更新 - foreach ($includeFile as $path => $time) { - if (is_file($path) && filemtime($path) > $time) { - // 模板文件如果有更新则缓存需要更新 - return false; - } - } - } - // 检查编译存储是否有效 - return $this->storage->check($cacheFile, $this->config['cache_time']); + // 未开启缓存功能 + if (!$this->config['tpl_cache']) { + return false; + } + // 缓存文件不存在 + if (!is_file($cacheFile)) { + return false; + } + // 读取缓存文件失败 + if (!$handle = @fopen($cacheFile, "r")) { + return false; + } + // 读取第一行 + preg_match('/\/\*(.+?)\*\//', fgets($handle), $matches); + if (!isset($matches[1])) { + return false; + } + $includeFile = unserialize($matches[1]); + if (!is_array($includeFile)) { + return false; + } + // 检查模板文件是否有更新 + foreach ($includeFile as $path => $time) { + if (is_file($path) && filemtime($path) > $time) { + // 模板文件如果有更新则缓存需要更新 + return false; } } - return false; + // 检查编译存储是否有效 + return $this->storage->check($cacheFile, $this->config['cache_time']); } /**