优代部分代码;block标签内可以使用{__block__}来引用所继承模板中相应block标签的内容;

模板包含文件记录及更新时间直接写入缓存的模板中;改进标签别名的处理方式,别名不再定义方法;
去除include标签传参自动生成变量的代码;cx类增加function方法,用来生成匿名函数,结合{~$函数名()}可用于递归的实现。
This commit is contained in:
oldrind
2016-03-11 21:58:18 +08:00
parent 542a3333d6
commit 71dbdcb874
9 changed files with 390 additions and 413 deletions

View File

@@ -38,42 +38,37 @@ class File
* 读取编译编译
* @string $cacheFile 缓存的文件名
* @array $vars 变量数组
* @boolean $isReturn 是否返回内容
* @return void|array
* @return void
*/
public function read($cacheFile, $vars = [], $isReturn = false)
public function read($cacheFile, $vars = [])
{
if (!empty($vars) && is_array($vars)) {
// 模板阵列变量分解成为独立变量
extract($vars, EXTR_OVERWRITE);
}
if ($isReturn) {
//载入模版缓存文件
include $cacheFile;
} else {
return include $cacheFile;
}
//载入模版缓存文件
include $cacheFile;
}
/**
* 检查编译缓存是否有效
* @array $template 用到的模板更新时间列表
* @array $templates 用到的模板更新时间列表
* @string $cacheFile 缓存的文件名
* @int $cacheTime 缓存时间
* @return boolean
*/
public function check($files, $cacheFile, $cacheTime)
public function check($templates, $cacheFile, $cacheTime)
{
foreach($files as $time => $path) {
if (is_file($path) && filemtime($path) > $time) {
// 模板文件如果有更新则缓存需要更新
return false;
}
}
if (0 != $cacheTime && time() > filemtime($cacheFile) + $cacheTime) {
// 缓存是否在有效期
return false;
}
foreach($templates as $time => $path) {
if (is_file($path) && filemtime($path) > $time + $cacheTime) {
// 模板文件如果有更新则缓存需要更新
return false;
}
}
return true;
}
}