Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 创建扫描多个级别的模板引擎(递归模板引擎)_Php_Oop_Recursion_Templating - Fatal编程技术网

Php 创建扫描多个级别的模板引擎(递归模板引擎)

Php 创建扫描多个级别的模板引擎(递归模板引擎),php,oop,recursion,templating,Php,Oop,Recursion,Templating,我正在开发一个模板引擎,但需要一些帮助。这是面向对象的定制CMF/CMS 目前,我从mysql支持的每个文档中获取信息,但我缓存文档,然后使用fte类处理它们: 我的代码只适用于第一级,我的意思是它不会扫描代码段中的系统代码段,而是扫描系统代码段中的代码段。 因此,代码按照系统代码段->自定义代码段->代码段的顺序进行扫描 关于如何让我的代码扫描多个级别,或者我认为它是递归的,但最多只有4个级别,这样用户就不会因为代码段、代码段内部、代码段内部等而过载 你也可以看到我可以重新扫描片段,但这不是我

我正在开发一个模板引擎,但需要一些帮助。这是面向对象的定制CMF/CMS

目前,我从mysql支持的每个文档中获取信息,但我缓存文档,然后使用fte类处理它们:

我的代码只适用于第一级,我的意思是它不会扫描代码段中的系统代码段,而是扫描系统代码段中的代码段。 因此,代码按照系统代码段->自定义代码段->代码段的顺序进行扫描

关于如何让我的代码扫描多个级别,或者我认为它是递归的,但最多只有4个级别,这样用户就不会因为代码段、代码段内部、代码段内部等而过载


你也可以看到我可以重新扫描片段,但这不是我想要实现的,对我来说,重复代码来解决这个问题感觉很糟糕。

PHP本身就是一种模板语言,如果你让你的模板类利用PHP本身进行模板化,那么做起来会很容易。我知道PHP是一种模板语言,但我正在尝试这样做,你有什么建议吗?
<?php
/* FTE Class */
class fte {
    public $id;
    public $output;

    public function __construct($id, $data) {
        $this->id = $id;
        $this->output = $data;
    }

    public function process() {
        ob_start();
        include(CORE_PATH . 'assets/cache/documents/cache.' . $this->id . '.php');
        /* Settings */
        if(isset($cache['settings'])) {
            foreach($cache['settings'] as $key => $value) {
                $scan = "[@$key]";
                $replace = $value;
                $this->output = str_replace($scan, $replace, $this->output);
            }
        }
        /* System Snippet */
        if(isset($cache['system'])) {
            foreach($cache['system'] as $key => $value) {
                $scan = "[@$value]";
                $replace = $cache['document'][$value];
                $this->output = str_replace($scan, $replace, $this->output);
            }
        }
        /* Custom Snippet */
        if(isset($cache['custom'])) {
            foreach($cache['custom'] as $key => $value) {
                $scan = "{{@$key})";
                $replace = $value;
                $this->output = str_replace($scan, $replace, $this->output);
            }
        }
        /* Snippet */
        if(isset($cache['snippet'])) {
            foreach($cache['snippet'] as $key => $value) {
                $scan = "{@$key}";
                $replace = $value;
                $this->output = str_replace($scan, $replace, $this->output);
            }
        }

        /* Return */
        return $this->output;
        ob_end_flush();  
    }
}
?>
[@] - System Snippets
{{@}} - Custom Snippets
{@} - Snippets