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: touch($file);
30: }
31: return file_get_contents($file);
32: }
33:
34:
35: /**
36: * @return bool
37: */
38: public function isExpired($file, $time)
39: {
40: return @filemtime($file) > $time; // @ - stat may fail
41: }
42:
43:
44: /**
45: * Returns fully qualified template name.
46: * @return string
47: */
48: public function getChildName($file, $parent = NULL)
49: {
50: if ($parent && !preg_match('#/|\\\\|[a-z][a-z0-9+.-]*:#iA', $file)) {
51: $file = dirname($parent) . '/' . $file;
52: }
53: return $file;
54: }
55:
56: }
57: