From 8069e235fd2971675ee5fc05026ffa9bce5cbbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Aug 2013 22:43:56 +0200 Subject: move Twig in 3rdparty --- inc/3rdparty/Twig/Gettext/Loader/Filesystem.php | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 inc/3rdparty/Twig/Gettext/Loader/Filesystem.php (limited to 'inc/3rdparty/Twig/Gettext/Loader') diff --git a/inc/3rdparty/Twig/Gettext/Loader/Filesystem.php b/inc/3rdparty/Twig/Gettext/Loader/Filesystem.php new file mode 100644 index 00000000..b011b032 --- /dev/null +++ b/inc/3rdparty/Twig/Gettext/Loader/Filesystem.php @@ -0,0 +1,58 @@ + + * + * 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 Саша Стаменковић + */ +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'; + } +} -- cgit v1.2.3