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: * @author David Grudl
17: */
18: class FileLoader extends Latte\Object implements Latte\ILoader
19: {
20:
21: /**
22: * Returns template source code.
23: * @return string
24: */
25: public function getContent($file)
26: {
27: if (!is_file($file)) {
28: throw new \RuntimeException("Missing template file '$file'.");
29:
30: } elseif ($this->isExpired($file, time())) {
31: touch($file);
32: }
33: return file_get_contents($file);
34: }
35:
36:
37: /**
38: * @return bool
39: */
40: public function isExpired($file, $time)
41: {
42: return @filemtime($file) > $time; // @ - stat may fail
43: }
44:
45:
46: /**
47: * Returns fully qualified template name.
48: * @return string
49: */
50: public function getChildName($file, $parent = NULL)
51: {
52: if ($parent && !preg_match('#/|\\\\|[a-z][a-z0-9+.-]*:#iA', $file)) {
53: $file = dirname($parent) . '/' . $file;
54: }
55: return $file;
56: }
57:
58: }
59: