Compatibility with Twig 1.27

This commit is contained in:
Xavier HAUSHERR 2016-10-27 09:19:56 +02:00 committed by Fabien Potencier
parent ed11f22360
commit 77c5395a79
2 changed files with 19 additions and 1 deletions

View File

@ -58,6 +58,7 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
* @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
*
* @return string The path to the template file
*
@ -87,7 +88,11 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
}
if (false === $file || null === $file) {
throw $twigLoaderException;
if ($throw) {
throw $twigLoaderException;
}
return false;
}
return $this->cache[$logicalName] = $file;

View File

@ -115,4 +115,17 @@ class FilesystemLoaderTest extends TestCase
$method->setAccessible(true);
$method->invoke($loader, 'name.format.engine');
}
public function testTwigSoftErrorIfTemplateDoesNotExist()
{
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
$loader = new FilesystemLoader($locator, $parser);
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views');
$method = new \ReflectionMethod('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader', 'findTemplate');
$method->setAccessible(true);
$this->assertFalse($method->invoke($loader, 'name.format.engine', false));
}
}