From: Chris Smith Date: Fri, 28 Jun 2013 09:26:16 +0000 (+0100) Subject: Use a constant for the main namespace X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f80bab25d34517b93bf2aa0d690ea13ac2c19417;p=konrad%2Ftwig.git Use a constant for the main namespace --- diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index f9211cb..d47781a 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -16,6 +16,9 @@ */ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { + /** Identifier of the main namespace. */ + const MAIN_NAMESPACE = '__main__'; + protected $paths; protected $cache; @@ -38,7 +41,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI * * @return array The array of paths where to look for templates */ - public function getPaths($namespace = '__main__') + public function getPaths($namespace = self::MAIN_NAMESPACE) { return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array(); } @@ -46,7 +49,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI /** * Returns the path namespaces. * - * The "__main__" namespace is always defined. + * The main namespace is always defined. * * @return array The array of defined namespaces */ @@ -61,7 +64,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI * @param string|array $paths A path or an array of paths where to look for templates * @param string $namespace A path namespace */ - public function setPaths($paths, $namespace = '__main__') + public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) { if (!is_array($paths)) { $paths = array($paths); @@ -81,7 +84,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI * * @throws Twig_Error_Loader */ - public function addPath($path, $namespace = '__main__') + public function addPath($path, $namespace = self::MAIN_NAMESPACE) { // invalidate the cache $this->cache = array(); @@ -101,7 +104,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI * * @throws Twig_Error_Loader */ - public function prependPath($path, $namespace = '__main__') + public function prependPath($path, $namespace = self::MAIN_NAMESPACE) { // invalidate the cache $this->cache = array(); @@ -175,7 +178,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI $this->validateName($name); - $namespace = '__main__'; + $namespace = self::MAIN_NAMESPACE; if (isset($name[0]) && '@' == $name[0]) { if (false === $pos = strpos($name, '/')) { throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index c3f6ece..4c874b6 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -89,9 +89,9 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase public function testGetNamespaces() { $loader = new Twig_Loader_Filesystem(sys_get_temp_dir()); - $this->assertEquals(array('__main__'), $loader->getNamespaces()); + $this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE), $loader->getNamespaces()); $loader->addPath(sys_get_temp_dir(), 'named'); - $this->assertEquals(array('__main__', 'named'), $loader->getNamespaces()); + $this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'), $loader->getNamespaces()); } }