如何实现java Servlet,PHP CMS模板等自动编译?

时间:2014-01-13 04:04:48

标签: java php templates smarty

我想实现像smarty这样的小型PHP模板引擎,它允许我编写自己的php标签(如果,for ..)

现在,我的问题是如何在修改模板文件时自动编译?

例如:Servlet。当我们修改servlet并等待几秒钟时,eclipse会告诉你修改后的servlet类被重新编译了!

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:0)

您可以检查缓存的已编译模板与源文件之间的修改日期。

$cacheFileAge = @filemtime($this->cacheFile); //Get Time
foreach(array_merge(array($template),$this->snipFiles) as $f)
  if($cacheFileAge < filemtime($f)) //Compare every template to cache file
    return $this->parse(file_get_contents($template)); //If cache file older than one, re-compile it
debugLog("Using Cached file ({$this->cacheFile})");
include($this->cacheFile); //use cached file

此示例来自另一个php模板项目HAMLE