diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index 2c854db8f..45ad32329 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -70,26 +70,22 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf { $exceptions = array(); foreach ($this->loaders as $loader) { - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - continue; - } - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { - return $loader->getSourceContext($name); + if ($loader instanceof Twig_SourceContextLoaderInterface) { + return $loader->getSourceContext($name); + } + + return new Twig_Source($loader->getSource($name), $name); } catch (Twig_Error_Loader $e) { $exceptions[] = $e->getMessage(); } } - if ($exceptions) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - - return new Twig_Source($this->getSource($name), $name); + throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } /** diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index 67a722d4b..c2b389653 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -27,6 +27,7 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase $path = dirname(__FILE__).'/../Fixtures'; $loader = new Twig_Loader_Chain(array( new Twig_Loader_Array(array('foo' => 'bar')), + new Twig_Loader_Array(array('errors/index.html' => 'baz')), new Twig_Loader_Filesystem(array($path)), )); @@ -34,7 +35,12 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase $this->assertNull($loader->getSourceContext('foo')->getPath()); $this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName()); - $this->assertEquals(realpath($path.'/errors/index.html'), realpath($loader->getSourceContext('errors/index.html')->getPath())); + $this->assertNull($loader->getSourceContext('errors/index.html')->getPath()); + $this->assertEquals('baz', $loader->getSourceContext('errors/index.html')->getCode()); + + $this->assertEquals('errors/base.html', $loader->getSourceContext('errors/base.html')->getName()); + $this->assertEquals(realpath($path.'/errors/base.html'), realpath($loader->getSourceContext('errors/base.html')->getPath())); + $this->assertNotEquals('baz', $loader->getSourceContext('errors/base.html')->getCode()); } /**