1: <?php
2:
3: /**
4: * This file is part of the Latte (https://latte.nette.org)
5: * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Latte\Loaders;
9:
10: use Latte;
11:
12:
13: /**
14: * Template loader.
15: */
16: class FileLoader extends Latte\Object implements Latte\ILoader
17: {
18:
19: /**
20: * Returns template source code.
21: * @return string
22: */
23: public function getContent($file)
24: {
25: if (!is_file($file)) {
26: throw new \RuntimeException("Missing template file '$file'.");
27:
28: } elseif ($this->isExpired($file, time())) {
29: if (@touch($file) === FALSE) {
30: $tmp = error_get_last();
31: trigger_error("File's modification time is in the future. Cannot update it: $tmp[message]", E_USER_WARNING);
32: }
33: }
34: return file_get_contents($file);
35: }
36:
37:
38: /**
39: * @return bool
40: */
41: public function isExpired($file, $time)
42: {
43: return @filemtime($file) > $time; // @ - stat may fail
44: }
45:
46:
47: /**
48: * Returns fully qualified template name.
49: * @return string
50: */
51: public function getChildName($file, $parent = NULL)
52: {
53: if ($parent && !preg_match('#/|\\\\|[a-z][a-z0-9+.-]*:#iA', $file)) {
54: $file = dirname($parent) . '/' . $file;
55: }
56: return $file;
57: }
58:
59: }
60: