public static function compile() { self::$contents = preg_replace(self::pattern(self::$start, self::$close), self::replace(), self::$contents); preg_match_all('/\\<\\?php \\}?(if|else if) .+\\?\\>/', self::$contents, $matchs); if ($matchs[0]) { foreach ($matchs[0] as $v) { $tmp = preg_replace('/\\$([a-zA-Z][\\w]*)([^=><!])?/', '$this->variables["\\1"]\\2', $v); self::$contents = preg_replace('/' . preg_quote($v) . '/', $tmp, self::$contents); } } }
/** * 编译模板内容 * @param String $tplfile 模板文件 * @param String $tmpfile 编译文件 * @return Void */ public static function execute($tplfile, $tmpfile) { self::$start = preg_quote(self::$delimiter[0]); self::$close = preg_quote(self::$delimiter[1]); self::$contents = file_get_contents($tplfile); //清除phpcode self::$contents = preg_replace("/\\<\\?php.*\\?\\>(\r\n)*/i", '', self::$contents); Ada_Template_Compile_Include::incfile(self::$start, self::$close); Ada_Template_Compile_Syntax::compile(); Ada_Template_Compile_Include::compile(); Ada_Template_Compile_Loop::compile(); Ada_Template_Compile_Choose::compile(); file_put_contents($tmpfile, self::$tplscript . self::$contents); }