-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathNamespaceLoader.php
More file actions
87 lines (65 loc) · 1.49 KB
/
NamespaceLoader.php
File metadata and controls
87 lines (65 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* This file is part of the Latte (https://latte.nette.org)
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Latte\Loaders;
use Latte;
/**
* Template loader.
*/
class NamespaceLoader implements Latte\Loader
{
/**
* @var Latte\Loader[]
*/
private array $loaders;
public function __construct(array $loaders)
{
$this->loaders = $loaders;
}
/**
* Returns template source code.
*/
public function getContent(string $name): string
{
[$loader, $name] = $this->extractLoaderAndName($name);
return $loader->getContent($name);
}
public function isExpired(string $file, int $time): bool
{
[$loader, $name] = $this->extractLoaderAndName($file);
return $loader->isExpired($name, $time);
}
/**
* Returns referred template name.
*/
public function getReferredName(string $name, string $referringName): string
{
[$loader, $name] = $this->extractLoaderAndName($name);
return $loader->getReferredName($name, $referringName);
}
/**
* Returns unique identifier for caching.
*/
public function getUniqueId(string $name): string
{
[$loader, $name] = $this->extractLoaderAndName($name);
return $loader->getUniqueId($name);
}
private function extractLoaderAndName(string $name): array
{
$namespaceParts = \explode('::', $name, 2);
if (count($namespaceParts) === 2) {
return [
$this->loaders[$namespaceParts[0]],
$namespaceParts[1],
];
}
return [
$this->loaders[''],
$name,
];
}
}