[Twig] Remove dead code

This commit is contained in:
Fabien Potencier 2019-09-17 12:18:13 +02:00
parent 8535416d25
commit 786d136b5e
4 changed files with 6 additions and 38 deletions

View File

@ -34,9 +34,7 @@ class FormThemeTokenParserTest extends TestCase
$stream = $env->tokenize($source);
$parser = new Parser($env);
if (method_exists($expected, 'setSourceContext')) {
$expected->setSourceContext($source);
}
$expected->setSourceContext($source);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
}

View File

@ -89,13 +89,10 @@ class TwigExtractorTest extends TestCase
try {
$extractor->extract($resources, new MessageCatalogue('en'));
} catch (Error $e) {
if (method_exists($e, 'getSourceContext')) {
$this->assertSame(\dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', \DIRECTORY_SEPARATOR), $e->getFile());
$this->assertSame(1, $e->getLine());
$this->assertSame('Unclosed "block".', $e->getMessage());
} else {
$this->expectExceptionMessageRegExp('/Unclosed "block" in ".*extractor(\\/|\\\\)syntax_error\\.twig" at line 1/');
}
$this->assertSame(\dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', \DIRECTORY_SEPARATOR), $e->getFile());
$this->assertSame(1, $e->getLine());
$this->assertSame('Unclosed "block".', $e->getMessage());
throw $e;
}
}

View File

@ -61,11 +61,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
if ($file instanceof \SplFileInfo) {
$path = $file->getRealPath() ?: $file->getPathname();
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new Source('', $name, $path));
} else {
$e->setTemplateName($name);
}
$e->setSourceContext(new Source('', $name, $path));
}
throw $e;

View File

@ -13,7 +13,6 @@ namespace Symfony\Bundle\TwigBundle;
use Symfony\Bridge\Twig\TwigEngine as BaseEngine;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\TemplateNameParserInterface;
@ -36,28 +35,6 @@ class TwigEngine extends BaseEngine implements EngineInterface
$this->locator = $locator;
}
/**
* {@inheritdoc}
*/
public function render($name, array $parameters = [])
{
try {
return parent::render($name, $parameters);
} catch (Error $e) {
if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) {
try {
// try to get the real name of the template where the error occurred
$name = $e->getTemplateName();
$path = (string) $this->locator->locate($this->parser->parse($name));
$e->setTemplateName($path);
} catch (\Exception $e2) {
}
}
throw $e;
}
}
/**
* {@inheritdoc}
*