src/Leevel/View/Parser.php
public function doCompile(string $file, ?string $cachePath = null, bool $isContent = false)
    {
        // 源码
        if (false === $isContent) {
            if (!is_file($file)) {
                throw new InvalidArgumentException(
                    sprintf('File %s is not exits.', $file)
                );
            }

            $cache = file_get_contents($file);

            $this->sourceFile = $file;
            $this->cachePath = $cachePath;
        } else {
            $cache = $file;
        }

        // 逐个载入分析器编译模板
        foreach ($this->parses as $parser) {
            // 清理对象 & 构建顶层树对象
            $this->clearThemeTree();

            $theme = [
                'source'   => $cache,
                'content'  => $cache,
                'position' => $this->getPosition($cache, '', 0),
            ];

            $theme = $this->normalizeThemeStruct($theme);
            $this->topTheme($theme);

            // 分析模板生成模板树
            $parser = $parser.'Parse';

            // 分析
            $this->{$parser}($cache);

            // 编译模板树
            $cache = $this->compileThemeTree();
        }

        // 生成编译文件
        if (null !== $cachePath) {
            $this->makeCacheFile($cachePath, $cache);
        } else {
            return $cache;
        }
    }
public function doCompile(string $file, ?string $cachePath = null, bool $isContent = false)
    {
        // 源码
        if (false === $isContent) {
            if (!is_file($file)) {
                throw new InvalidArgumentException(
                    sprintf('File %s is not exits.', $file)
                );
            }

            $cache = file_get_contents($file);

            $this->sourceFile = $file;
            $this->cachePath = $cachePath;
        } else {
            $cache = $file;
        }

        // 逐个载入分析器编译模板
        foreach ($this->parses as $parser) {
            // 清理对象 & 构建顶层树对象
            $this->clearThemeTree();

            $theme = [
                'source'   => $cache,
                'content'  => $cache,
                'position' => $this->getPosition($cache, '', 0),
            ];

            $theme = $this->normalizeThemeStruct($theme);
            $this->topTheme($theme);

            // 分析模板生成模板树
            $parser = $parser.'Parse';

            // 分析
            $this->{$parser}($cache);

            // 编译模板树
            $cache = $this->compileThemeTree();
        }

        // 生成编译文件
        if (null !== $cachePath) {
            $this->makeCacheFile($cachePath, $cache);
        } else {
            return $cache;
        }
    }
执行编译.

@param string      $file
@param null|string $cachePath
@param bool        $isContent

@return string|void