think\Template::parseLiteral PHP Method

parseLiteral() private method

替换页面中的literal标签
private parseLiteral ( string &$content, boolean $restore = false ) : void
$content string 模板内容
$restore boolean 是否为还原
return void
    private function parseLiteral(&$content, $restore = false)
    {
        $regex = $this->getRegex($restore ? 'restoreliteral' : 'literal');
        if (preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) {
            if (!$restore) {
                $count = count($this->literal);
                // 替换literal标签
                foreach ($matches as $match) {
                    $this->literal[] = substr($match[0], strlen($match[1]), -strlen($match[2]));
                    $content = str_replace($match[0], "<!--###literal{$count}###-->", $content);
                    $count++;
                }
            } else {
                // 还原literal标签
                foreach ($matches as $match) {
                    $content = str_replace($match[0], $this->literal[$match[1]], $content);
                }
                // 清空literal记录
                $this->literal = [];
            }
            unset($matches);
        }
        return;
    }