[Templating] added a isFresh() method to Loader classes

This commit is contained in:
Fabien Potencier 2010-05-20 17:15:36 +02:00
parent 8f112ae261
commit f11d539420
4 changed files with 56 additions and 0 deletions

View File

@ -95,4 +95,16 @@ class CacheLoader extends Loader
return new FileStorage($path, $options['renderer']);
}
/**
* Returns true if the template is still fresh.
*
* @param string $template The template name
* @param array $options An array of options
* @param timestamp $time The last modification time of the cached template
*/
public function isFresh($template, array $options = array(), $time)
{
return $this->loader->isFresh($template, $options);
}
}

View File

@ -67,4 +67,22 @@ class ChainLoader extends Loader
return false;
}
/**
* Returns true if the template is still fresh.
*
* @param string $template The template name
* @param array $options An array of options
* @param timestamp $time The last modification time of the cached template
*/
public function isFresh($template, array $options = array(), $time)
{
foreach ($this->loaders as $loader) {
if (false !== $ret = $loader->load($template, $options)) {
return $loader->isFresh($template, $options);
}
}
return false;
}
}

View File

@ -87,6 +87,23 @@ class FilesystemLoader extends Loader
return false;
}
/**
* Returns true if the template is still fresh.
*
* @param string $template The template name
* @param array $options An array of options
* @param timestamp $time The last modification time of the cached template
*/
public function isFresh($template, array $options = array(), $time)
{
if (false === $template = $this->load($template, $options))
{
return false;
}
return filemtime((string) $template) < $time;
}
/**
* Returns true if the file is an existing absolute path.
*

View File

@ -29,4 +29,13 @@ interface LoaderInterface
* @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise
*/
function load($template, array $options = array());
/**
* Returns true if the template is still fresh.
*
* @param string $template The template name
* @param array $options An array of options
* @param timestamp $time The last modification time of the cached template
*/
function isFresh($template, array $options = array(), $time);
}