Skip to content

Commit

Permalink
改进模板变量多次渲染混淆的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 4, 2019
1 parent 3fb2741 commit 1db0078
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public function __construct(array $config = [])
/**
* 模板变量赋值
* @access public
* @param mixed $name
* @param mixed $value
* @param array $vars 模板变量
* @return $this
*/
public function assign(array $vars = [])
Expand Down Expand Up @@ -222,9 +221,8 @@ public function extend(string $rule, callable $callback = null): void
*/
public function fetch(string $template, array $vars = []): void
{
if ($vars) {
$this->data = array_merge($this->data, $vars);
}

$data = $vars ? array_merge($this->data, $vars) : $this->data;

if (!empty($this->config['cache_id']) && $this->config['display_cache'] && $this->cache) {
// 读取渲染缓存
Expand All @@ -250,7 +248,7 @@ public function fetch(string $template, array $vars = []): void
ob_implicit_flush(0);

// 读取编译存储
$this->storage->read($cacheFile, $this->data);
$this->storage->read($cacheFile, $data);

// 获取并清空缓存
$content = ob_get_clean();
Expand Down Expand Up @@ -289,9 +287,7 @@ public function isCache(string $cacheId): bool
*/
public function display(string $content, array $vars = []): void
{
if ($vars) {
$this->data = array_merge($this->data, $vars);
}
$data = $vars ? array_merge($this->data, $vars) : $this->data;

$cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($content) . '.' . ltrim($this->config['cache_suffix'], '.');

Expand All @@ -301,7 +297,7 @@ public function display(string $content, array $vars = []): void
}

// 读取编译存储
$this->storage->read($cacheFile, $this->data);
$this->storage->read($cacheFile, $data);
}

/**
Expand Down

0 comments on commit 1db0078

Please sign in to comment.