コード例 #1
0
ファイル: Compile.php プロジェクト: adawongframework/project
 /**
  * 编译模板内容
  * @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);
 }
コード例 #2
0
ファイル: Include.php プロジェクト: adawongframework/project
 /**
  * 查找和替换被包含的文件
  * 没有实现深度包含文件
  *+----------------------
  * @param Void
  * @return Void
  */
 public static function incfile($stat, $close)
 {
     $pattern = '/(?:' . self::$start . '[\\s]*template[\\s]+%s[\\s]*\\/[\\s]*' . $close . ')+/U';
     preg_match_all(sprintf($pattern, self::$pattern['file'] . '\\.' . self::$tplsuffix), self::$contents, $matchs);
     $files = array();
     //获取被包含的文件内容
     if ($matchs[1]) {
         foreach ($matchs[1] as $file) {
             $file .= '.' . self::$tplsuffix;
             if (!is_file($file)) {
                 throw new Ada_Exception('tpl ' . $file . ' file Not Found');
             }
             $files[$file] = file_get_contents($file);
         }
     }
     //获取包含文件内容替换到包含位置
     foreach ($files as $file => $text) {
         self::$contents = preg_replace(sprintf($pattern, $file), $text, self::$contents);
     }
     unset($matchs, $files);
 }