mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
added cache reloading when auto_reload is true and an extension has been modified
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.3.0
|
||||
|
||||
* added cache reloading when auto_reload is true and an extension has been modified
|
||||
* added the possibility to force the escaping of a string already marked as safe (instance of Twig_Markup)
|
||||
* allowed empty templates to be used as traits
|
||||
* added traits support for the "parent" function
|
||||
|
||||
@@ -301,7 +301,7 @@ class Twig_Environment
|
||||
if (false === $cache = $this->getCacheFilename($name)) {
|
||||
eval('?>'.$this->compileSource($this->loader->getSource($name), $name));
|
||||
} else {
|
||||
if (!is_file($cache) || ($this->isAutoReload() && !$this->loader->isFresh($name, filemtime($cache)))) {
|
||||
if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
|
||||
$this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $name));
|
||||
}
|
||||
|
||||
@@ -316,6 +316,30 @@ class Twig_Environment
|
||||
return $this->loadedTemplates[$cls] = new $cls($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the template is still fresh.
|
||||
*
|
||||
* Besides checking the loader for freshness information,
|
||||
* this method also checks if the enabled extensions have
|
||||
* not changed.
|
||||
*
|
||||
* @param string $name The template name
|
||||
* @param timestamp $time The last modification time of the cached template
|
||||
*
|
||||
* @return Boolean true if the template is fresh, false otherwise
|
||||
*/
|
||||
public function isTemplateFresh($name, $time)
|
||||
{
|
||||
foreach ($this->extensions as $extension) {
|
||||
$r = new ReflectionObject($extension);
|
||||
if (filemtime($r->getFileName()) > $time) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->loader->isFresh($name, $time);
|
||||
}
|
||||
|
||||
public function resolveTemplate($names)
|
||||
{
|
||||
if (!is_array($names)) {
|
||||
|
||||
Reference in New Issue
Block a user