From d472d21515e6616da447a0bf7c2b891d6b79cd19 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 24 Sep 2011 08:05:14 +0200 Subject: [PATCH] added cache reloading when auto_reload is true and an extension has been modified --- CHANGELOG | 1 + lib/Twig/Environment.php | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2d3a209..41b2da3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index b4c28c7..dd11538 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -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)) { -- 1.7.2.5