From 11a8f31c5a58bb94c0c6a9172bc5d88503d4856f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 15 Jan 2011 12:05:44 +0100 Subject: [PATCH] made Twig_Loader_Filesystem more flexible --- lib/Twig/Loader/Filesystem.php | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-) 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))); } } -- 1.7.2.5