mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
fixed Twig_Loader_Chain logic
This commit is contained in:
@@ -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).')' : ''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user