From 203af9a649288410d5052c4e8b6e86823f3b2eec Mon Sep 17 00:00:00 2001 From: fabien Date: Wed, 14 Oct 2009 05:06:16 +0000 Subject: [PATCH] added a getPaths() method to the filesystem loader git-svn-id: http://svn.twig-project.org/trunk@38 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- lib/Twig/Loader/Filesystem.php | 34 ++++++++++++++++++++++------------ 1 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index cbceb9b..a6f5de9 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -18,34 +18,44 @@ */ class Twig_Loader_Filesystem extends Twig_Loader { - protected $folders; + protected $paths; /** * Constructor. * - * @param string|array $folders A folder or an array of folders where to look for templates + * @param string|array $paths A path or an array of paths where to look for templates * @param string $cache The compiler cache directory * @param Boolean $autoReload Whether to reload the template is the original source changed * * @see Twig_Loader */ - public function __construct($folders, $cache = null, $autoReload = true) + public function __construct($paths, $cache = null, $autoReload = true) { - if (!is_array($folders)) + if (!is_array($paths)) { - $folders = array($folders); + $paths = array($paths); } - $this->folders = array(); - foreach ($folders as $folder) + $this->paths = array(); + foreach ($paths as $path) { - $this->folders[] = realpath($folder); + $this->paths[] = realpath($path); } parent::__construct($cache, $autoReload); } /** + * Returns the paths to the templates. + * + * @return array The array of paths where to look for templates + */ + public function getPaths() + { + return $this->paths; + } + + /** * Gets the source code of a template, given its name. * * @param string $name string The name of the template to load @@ -56,17 +66,17 @@ class Twig_Loader_Filesystem extends Twig_Loader */ public function getSource($name) { - foreach ($this->folders as $folder) + foreach ($this->paths as $path) { - $file = realpath($folder.DIRECTORY_SEPARATOR.$name); + $file = realpath($path.DIRECTORY_SEPARATOR.$name); - if (0 !== strpos($file, $folder)) + if (0 !== strpos($file, $path)) { continue; } // simple security check - if (0 !== strpos($file, $folder)) + if (0 !== strpos($file, $path)) { throw new RuntimeException('Looks like you try to load a template outside configured directories.'); } -- 1.7.2.5