8000 Compatibility with Twig 1.27 · symfony/symfony@77c5395 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77c5395

Browse files
xkobalfabpot
authored andcommitted
Compatibility with Twig 1.27
1 parent ed11f22 commit 77c5395

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function exists($name)
5858
* Otherwise the template is located using the locator from the twig library.
5959
*
6060
* @param string|TemplateReferenceInterface $template The template
61+
* @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
6162
*
6263
* @return string The path to the template file
6364
*
@@ -87,7 +88,11 @@ protected function findTemplate($template, $throw = true)
8788
}
8889

8990
if (false === $file || null === $file) {
90-
throw $twigLoaderException;
91+
if ($throw) {
92+
throw $twigLoaderException;
93+
}
94+
95+
return false;
9196
}
9297

9398
return $this->cache[$logicalName] = $file;

src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,17 @@ public function testTwigErrorIfTemplateDoesNotExist()
115115
$method->setAccessible(true);
116116
$method->invoke($loader, 'name.format.engine');
117117
}
118+
119+
public function testTwigSoftErrorIfTemplateDoesNotExist()
120+
{
121+
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
122+
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
123+
124+
$loader = new FilesystemLoader($locator, $parser);
125+
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views');
126+
127+
$method = new \ReflectionMethod('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader', 'findTemplate');
128+
$method->setAccessible(true);
129+
$this->assertFalse($method->invoke($loader, 'name.format.engine', false));
130+
}
118131
}

0 commit comments

Comments
 (0)
0