From: Fabien Potencier Date: Sat, 15 Jan 2011 11:05:44 +0000 (+0100) Subject: made Twig_Loader_Filesystem more flexible X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=11a8f31c5a58bb94c0c6a9172bc5d88503d4856f;p=web%2Fkonrad%2Ftwig.git made Twig_Loader_Filesystem more flexible --- diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index d0f26d9..3e08f03 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -108,6 +108,19 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface return $this->cache[$name]; } + $this->validateName($name); + + foreach ($this->paths as $path) { + if (file_exists($path.'/'.$name) && !is_dir($path.'/'.$name)) { + return $this->cache[$name] = $path.'/'.$name; + } + } + + throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths))); + } + + protected function validateName($name) + { $parts = explode('/', $name); $level = 0; foreach ($parts as $part) { @@ -118,16 +131,8 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface } if ($level < 0) { - throw new Twig_Error_Loader('Looks like you try to load a template outside configured directories.'); + throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); } } - - foreach ($this->paths as $path) { - if (file_exists($path.'/'.$name) && !is_dir($path.'/'.$name)) { - return $this->cache[$name] = $path.'/'.$name; - } - } - - throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths))); } }