aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/Twig/Extensions/Gettext/Loader
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
commita4565e88edbc8e3bd092a475469769c86a4c350c (patch)
treea6a3c935b03a23ff87575c8c315cf8ba78fe68c2 /inc/Twig/Extensions/Gettext/Loader
parentf6c9baab3efeec1d0efa151e276fc08d5b58f9e9 (diff)
downloadwallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.gz
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.zst
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.zip
add Twig & refactor poche
Diffstat (limited to 'inc/Twig/Extensions/Gettext/Loader')
-rw-r--r--inc/Twig/Extensions/Gettext/Loader/Filesystem.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/inc/Twig/Extensions/Gettext/Loader/Filesystem.php b/inc/Twig/Extensions/Gettext/Loader/Filesystem.php
new file mode 100644
index 00000000..b011b032
--- /dev/null
+++ b/inc/Twig/Extensions/Gettext/Loader/Filesystem.php
@@ -0,0 +1,58 @@
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
12namespace Twig\Gettext\Loader;
13
14/**
15 * Loads template from the filesystem.
16 *
17 * @author Саша Стаменковић <umpirsky@gmail.com>
18 */
19class 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}