* 1.14.0 (2013-XX-XX)
+ * fixed the filesystem loader cache when a template name exists in several namespaces
* added support for calling macros defined in a template without importing them first
* added support for named arguments for macros
* replaced a PHP fatal error with an exception when a macro does not exist
$this->validateName($name);
$namespace = self::MAIN_NAMESPACE;
+ $shortname = $name;
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));
}
$namespace = substr($name, 1, $pos - 1);
-
- $name = substr($name, $pos + 1);
+ $shortname = substr($name, $pos + 1);
}
if (!isset($this->paths[$namespace])) {
}
foreach ($this->paths[$namespace] as $path) {
- if (is_file($path.'/'.$name)) {
- return $this->cache[$name] = $path.'/'.$name;
+ if (is_file($path.'/'.$shortname)) {
+ return $this->cache[$name] = $path.'/'.$shortname;
}
}
$loader->addPath(sys_get_temp_dir(), 'named');
$this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'), $loader->getNamespaces());
}
+
+ public function testFindTemplateExceptionNamespace()
+ {
+ $basePath = dirname(__FILE__).'/Fixtures';
+
+ $loader = new Twig_Loader_Filesystem(array($basePath.'/normal'));
+ $loader->addPath($basePath.'/named', 'named');
+
+ try {
+ $loader->getSource('@named/nowhere.html');
+ } catch (Exception $e) {
+ $this->assertInstanceof('Twig_Error_Loader', $e);
+ $this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage());
+ }
+ }
+
+ public function testFindTemplateWithCache()
+ {
+ $basePath = dirname(__FILE__).'/Fixtures';
+
+ $loader = new Twig_Loader_Filesystem(array($basePath.'/normal'));
+ $loader->addPath($basePath.'/named', 'named');
+
+ // prime the cache for index.html in the named namespace
+ $namedSource = $loader->getSource('@named/index.html');
+ $this->assertEquals("named path\n", $namedSource);
+
+ // get index.html from the main namespace
+ $this->assertEquals("path\n", $loader->getSource('index.html'));
+ }
}