blob: b011b032421f9b529968df457aae34a4ee44502e (
plain) (
blame)
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
|
<?php
/**
* This file is part of the Twig Gettext utility.
*
* (c) Саша Стаменковић <umpirsky@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Gettext\Loader;
/**
* Loads template from the filesystem.
*
* @author Саша Стаменковић <umpirsky@gmail.com>
*/
class Filesystem extends \Twig_Loader_Filesystem
{
/**
* Hacked find template to allow loading templates by absolute path.
*
* @param string $name template name or absolute path
*/
protected function findTemplate($name)
{
// normalize name
$name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
if (isset($this->cache[$name])) {
return $this->cache[$name];
}
$this->validateName($name);
$namespace = '__main__';
if (isset($name[0]) && '@' == $name[0]) {
if (false === $pos = strpos($name, '/')) {
throw new \InvalidArgumentException(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
}
$namespace = substr($name, 1, $pos - 1);
$name = substr($name, $pos + 1);
}
if (!isset($this->paths[$namespace])) {
throw new \Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace));
}
if (is_file($name)) {
return $this->cache[$name] = $name;
}
return __DIR__.'/../Test/Fixtures/twig/empty.twig';
}
}
|