Skip to content

Commit f11d539

Browse files
committed
[Templating] added a isFresh() method to Loader classes
1 parent 8f112ae commit f11d539

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/Symfony/Components/Templating/Loader/CacheLoader.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,16 @@ public function load($template, array $options = array())
9595

9696
return new FileStorage($path, $options['renderer']);
9797
}
98+
99+
/**
100+
* Returns true if the template is still fresh.
101+
*
102+
* @param string $template The template name
103+
* @param array $options An array of options
104+
* @param timestamp $time The last modification time of the cached template
105+
*/
106+
public function isFresh($template, array $options = array(), $time)
107+
{
108+
return $this->loader->isFresh($template, $options);
109+
}
98110
}

src/Symfony/Components/Templating/Loader/ChainLoader.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,22 @@ public function load($template, array $options = array())
6767

6868
return false;
6969
}
70+
71+
/**
72+
* Returns true if the template is still fresh.
73+
*
74+
* @param string $template The template name
75+
* @param array $options An array of options
76+
* @param timestamp $time The last modification time of the cached template
77+
*/
78+
public function isFresh($template, array $options = array(), $time)
79+
{
80+
foreach ($this->loaders as $loader) {
81+
if (false !== $ret = $loader->load($template, $options)) {
82+
return $loader->isFresh($template, $options);
83+
}
84+
}
85+
86+
return false;
87+
}
7088
}

src/Symfony/Components/Templating/Loader/FilesystemLoader.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ public function load($template, array $options = array())
8787
return false;
8888
}
8989

90+
/**
91+
* Returns true if the template is still fresh.
92+
*
93+
* @param string $template The template name
94+
* @param array $options An array of options
95+
* @param timestamp $time The last modification time of the cached template
96+
*/
97+
public function isFresh($template, array $options = array(), $time)
98+
{
99+
if (false === $template = $this->load($template, $options))
100+
{
101+
return false;
102+
}
103+
104+
return filemtime((string) $template) < $time;
105+
}
106+
90107
/**
91108
* Returns true if the file is an existing absolute path.
92109
*

src/Symfony/Components/Templating/Loader/LoaderInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ interface LoaderInterface
2929
* @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise
3030
*/
3131
function load($template, array $options = array());
32+
33+
/**
34+
* Returns true if the template is still fresh.
35+
*
36+
* @param string $template The template name
37+
* @param array $options An array of options
38+
* @param timestamp $time The last modification time of the cached template
39+
*/
40+
function isFresh($template, array $options = array(), $time);
3241
}

0 commit comments

Comments
 (0)