]>
Commit | Line | Data |
---|---|---|
a4565e88 NL |
1 | <?php |
2 | ||
3 | /** | |
4 | * This file is part of the Twig Gettext utility. | |
5 | * | |
6 | * (c) Саша Стаменковић <umpirsky@gmail.com> | |
7 | * | |
8 | * For the full copyright and license information, please view the LICENSE | |
9 | * file that was distributed with this source code. | |
10 | */ | |
11 | ||
12 | namespace Twig\Gettext\Loader; | |
13 | ||
14 | /** | |
15 | * Loads template from the filesystem. | |
16 | * | |
17 | * @author Саша Стаменковић <umpirsky@gmail.com> | |
18 | */ | |
19 | class Filesystem extends \Twig_Loader_Filesystem | |
20 | { | |
21 | /** | |
22 | * Hacked find template to allow loading templates by absolute path. | |
23 | * | |
24 | * @param string $name template name or absolute path | |
25 | */ | |
26 | protected function findTemplate($name) | |
27 | { | |
28 | // normalize name | |
29 | $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); | |
30 | ||
31 | if (isset($this->cache[$name])) { | |
32 | return $this->cache[$name]; | |
33 | } | |
34 | ||
35 | $this->validateName($name); | |
36 | ||
37 | $namespace = '__main__'; | |
38 | if (isset($name[0]) && '@' == $name[0]) { | |
39 | if (false === $pos = strpos($name, '/')) { | |
40 | throw new \InvalidArgumentException(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); | |
41 | } | |
42 | ||
43 | $namespace = substr($name, 1, $pos - 1); | |
44 | ||
45 | $name = substr($name, $pos + 1); | |
46 | } | |
47 | ||
48 | if (!isset($this->paths[$namespace])) { | |
49 | throw new \Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); | |
50 | } | |
51 | ||
52 | if (is_file($name)) { | |
53 | return $this->cache[$name] = $name; | |
54 | } | |
55 | ||
56 | return __DIR__.'/../Test/Fixtures/twig/empty.twig'; | |
57 | } | |
58 | } |