[Templating] added a isFresh() method to Loader classes
This commit is contained in:
parent
8f112ae261
commit
f11d539420
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user