Skip to content

Commit

Permalink
[Templating] added a isFresh() method to Loader classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 20, 2010
1 parent 8f112ae commit f11d539
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Symfony/Components/Templating/Loader/CacheLoader.php
Expand Up @@ -95,4 +95,16 @@ public function load($template, array $options = array())

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);
}
}
18 changes: 18 additions & 0 deletions src/Symfony/Components/Templating/Loader/ChainLoader.php
Expand Up @@ -67,4 +67,22 @@ public function load($template, array $options = array())

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;
}
}
17 changes: 17 additions & 0 deletions src/Symfony/Components/Templating/Loader/FilesystemLoader.php
Expand Up @@ -87,6 +87,23 @@ public function load($template, array $options = array())
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.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Components/Templating/Loader/LoaderInterface.php
Expand Up @@ -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);
}

0 comments on commit f11d539

Please sign in to comment.