renamed the default filesystem namespace to __main__

This commit is contained in:
Fabien Potencier
2012-07-17 08:23:39 +02:00
parent c34541dfb3
commit b9afa84571
2 changed files with 6 additions and 5 deletions
+5 -5
View File
@@ -37,7 +37,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
* *
* @return array The array of paths where to look for templates * @return array The array of paths where to look for templates
*/ */
public function getPaths($namespace = '') public function getPaths($namespace = '__main__')
{ {
return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array(); return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array();
} }
@@ -48,7 +48,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
* @param string|array $paths A path or an array of paths where to look for templates * @param string|array $paths A path or an array of paths where to look for templates
* @param string $namespace A path namespace * @param string $namespace A path namespace
*/ */
public function setPaths($paths, $namespace = '') public function setPaths($paths, $namespace = '__main__')
{ {
if (!is_array($paths)) { if (!is_array($paths)) {
$paths = array($paths); $paths = array($paths);
@@ -66,7 +66,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
* @param string $path A path where to look for templates * @param string $path A path where to look for templates
* @param string $namespace A path name * @param string $namespace A path name
*/ */
public function addPath($path, $namespace = '') public function addPath($path, $namespace = '__main__')
{ {
// invalidate the cache // invalidate the cache
$this->cache = array(); $this->cache = array();
@@ -84,7 +84,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
* @param string $path A path where to look for templates * @param string $path A path where to look for templates
* @param string $namespace A path name * @param string $namespace A path name
*/ */
public function prependPath($path, $namespace = '') public function prependPath($path, $namespace = '__main__')
{ {
// invalidate the cache // invalidate the cache
$this->cache = array(); $this->cache = array();
@@ -142,7 +142,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
$this->validateName($name); $this->validateName($name);
$namespace = ''; $namespace = '__main__';
if (isset($name[0]) && '@' == $name[0]) { if (isset($name[0]) && '@' == $name[0]) {
if (false === $pos = strpos($name, '/')) { if (false === $pos = strpos($name, '/')) {
throw new \InvalidArgumentException(sprintf('Malformed template name "%s".', $name)); throw new \InvalidArgumentException(sprintf('Malformed template name "%s".', $name));
@@ -75,6 +75,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
), $loader->getPaths('named')); ), $loader->getPaths('named'));
$this->assertEquals("path (final)\n", $loader->getSource('index.html')); $this->assertEquals("path (final)\n", $loader->getSource('index.html'));
$this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html'));
$this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
} }
} }