Skip to content

Commit

Permalink
修复模板引擎缓存文件在配置不当时可能通过浏览器访问源代码的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonweicn committed Jan 26, 2022
1 parent 611420e commit 916191c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions MiniFramework/Base/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ final public function render($script, $check = true)
if (TPL_ON === true) {

// 模板缓存key
$tplCacheKey = 'tpl_' . md5($script);
$tplCacheKey = md5($script);

// 模板缓存文件
$tplFile = CACHE_PATH . '/' . $tplCacheKey;
$tplCacheFile = CACHE_PATH . '/tpl_' . $tplCacheKey . '.php';

// 检查是否需要刷新模板缓存
$refreshCache = true;
if (file_exists($tplFile)) {
$cacheTime = filemtime($tplFile);
if (file_exists($tplCacheFile)) {
$cacheTime = filemtime($tplCacheFile);
$scriptTime = filemtime($script);
if ($cacheTime > $scriptTime) {
$refreshCache = false;
Expand All @@ -203,10 +203,10 @@ final public function render($script, $check = true)
// 刷新模板缓存
if ($refreshCache === true) {
$tplContent = file_get_contents($script);
file_put_contents($tplFile, $this->parseTpl($tplContent));
file_put_contents($tplCacheFile, $this->compiler($tplContent));
}

$script = $tplFile;
$script = $tplCacheFile;
}

if (SHOW_DEBUG === false) {
Expand Down Expand Up @@ -299,12 +299,12 @@ public function setJsFile($jsFileUrl)
}

/**
* 解析模板
* 模板引擎编译器
*
* @param string $content
* @return string
*/
public function parseTpl($content)
public function compiler($content)
{
$reg = "/\\" . TPL_SEPARATOR_L . "(.*?)\\" . TPL_SEPARATOR_R . "/";
$content = preg_replace_callback($reg, [
Expand Down

0 comments on commit 916191c

Please sign in to comment.