1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace ApiGen\Renderer\Latte; |
4: | |
5: | use Latte; |
6: | |
7: | use function is_file; |
8: | |
9: | |
10: | class LatteCascadingLoader implements Latte\Loader |
11: | { |
12: | |
13: | |
14: | |
15: | public function __construct( |
16: | protected array $baseDirs, |
17: | protected Latte\Loader $inner = new Latte\Loaders\FileLoader(), |
18: | ) { |
19: | } |
20: | |
21: | |
22: | public function getContent(string $name): string |
23: | { |
24: | foreach ($this->baseDirs as $baseDir) { |
25: | $path = $baseDir . '/' . $name; |
26: | |
27: | if (is_file($path)) { |
28: | return $this->inner->getContent($path); |
29: | } |
30: | } |
31: | |
32: | throw new Latte\RuntimeException("Missing template file '$name'."); |
33: | } |
34: | |
35: | |
36: | public function isExpired(string $name, int $time): bool |
37: | { |
38: | foreach ($this->baseDirs as $baseDir) { |
39: | $path = $baseDir . '/' . $name; |
40: | |
41: | if (is_file($path)) { |
42: | return $this->inner->isExpired($path, $time); |
43: | } |
44: | } |
45: | |
46: | throw new Latte\RuntimeException("Missing template file '$name'."); |
47: | } |
48: | |
49: | |
50: | public function getReferredName(string $name, string $referringName): string |
51: | { |
52: | return $this->inner->getReferredName($name, $referringName); |
53: | } |
54: | |
55: | |
56: | public function getUniqueId(string $name): string |
57: | { |
58: | foreach ($this->baseDirs as $baseDir) { |
59: | $path = $baseDir . '/' . $name; |
60: | |
61: | if (is_file($path)) { |
62: | return $this->inner->getUniqueId($path); |
63: | } |
64: | } |
65: | |
66: | throw new Latte\RuntimeException("Missing template file '$name'."); |
67: | } |
68: | } |
69: | |