bug #20831 [Twig] Fix deprecations with Twig 1.29 (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[Twig] Fix deprecations with Twig 1.29
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #20829
| License | MIT
| Doc PR | -
Commits
-------
9218cac
[Twig] Fix deprecations with Twig 1.29
This commit is contained in:
commit
be5a5e43e7
@ -72,8 +72,7 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error
|
* @expectedException \Twig_Error
|
||||||
* @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
|
|
||||||
* @dataProvider resourcesWithSyntaxErrorsProvider
|
* @dataProvider resourcesWithSyntaxErrorsProvider
|
||||||
*/
|
*/
|
||||||
public function testExtractSyntaxError($resources)
|
public function testExtractSyntaxError($resources)
|
||||||
@ -82,7 +81,19 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
|
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
|
||||||
|
|
||||||
$extractor = new TwigExtractor($twig);
|
$extractor = new TwigExtractor($twig);
|
||||||
$extractor->extract($resources, new MessageCatalogue('en'));
|
|
||||||
|
try {
|
||||||
|
$extractor->extract($resources, new MessageCatalogue('en'));
|
||||||
|
} catch (\Twig_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/');
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,10 +61,14 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
|||||||
try {
|
try {
|
||||||
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (\Twig_Error $e) {
|
||||||
if ($file instanceof SplFileInfo) {
|
if ($file instanceof \SplFileInfo) {
|
||||||
$e->setTemplateName($file->getRelativePathname());
|
$path = $file->getRealPath() ?: $file->getPathname();
|
||||||
} elseif ($file instanceof \SplFileInfo) {
|
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
|
||||||
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
|
if (method_exists($e, 'setSourceContext')) {
|
||||||
|
$e->setSourceContext(new \Twig_Source('', $name, $path));
|
||||||
|
} else {
|
||||||
|
$e->setTemplateName($name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -74,7 +74,13 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
|||||||
if ($name instanceof TemplateReference) {
|
if ($name instanceof TemplateReference) {
|
||||||
try {
|
try {
|
||||||
// try to get the real name of the template where the error occurred
|
// try to get the real name of the template where the error occurred
|
||||||
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
|
$name = $e->getTemplateName();
|
||||||
|
$path = (string) $this->locator->locate($this->parser->parse($name));
|
||||||
|
if (method_exists($e, 'setSourceContext')) {
|
||||||
|
$e->setSourceContext(new \Twig_Source('', $name, $path));
|
||||||
|
} else {
|
||||||
|
$e->setTemplateName($path);
|
||||||
|
}
|
||||||
} catch (\Exception $e2) {
|
} catch (\Exception $e2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,11 @@
|
|||||||
<ul id="menu-profiler">
|
<ul id="menu-profiler">
|
||||||
{% for name, template in templates %}
|
{% for name, template in templates %}
|
||||||
{% set menu -%}
|
{% set menu -%}
|
||||||
{% with { 'collector': profile.getcollector(name) } %}
|
{% if block('menu', template) is defined %}
|
||||||
{{- block('menu', template) -}}
|
{% with { 'collector': profile.getcollector(name) } %}
|
||||||
{% endwith %}
|
{{- block('menu', template) -}}
|
||||||
|
{% endwith %}
|
||||||
|
{% endif %}
|
||||||
{%- endset %}
|
{%- endset %}
|
||||||
{% if menu != '' %}
|
{% if menu != '' %}
|
||||||
<li class="{{ name }}{% if name == panel %} selected{% endif %}">
|
<li class="{{ name }}{% if name == panel %} selected{% endif %}">
|
||||||
|
@ -26,14 +26,16 @@
|
|||||||
|
|
||||||
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
|
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
|
||||||
{% for name, template in templates %}
|
{% for name, template in templates %}
|
||||||
{% with {
|
{% if block('toolbar', template) is defined %}
|
||||||
'collector': profile.getcollector(name),
|
{% with {
|
||||||
'profiler_url': profiler_url,
|
'collector': profile.getcollector(name),
|
||||||
'token': profile.token,
|
'profiler_url': profiler_url,
|
||||||
'name': name
|
'token': profile.token,
|
||||||
} %}
|
'name': name
|
||||||
{{ block('toolbar', template) }}
|
} %}
|
||||||
{% endwith %}
|
{{ block('toolbar', template) }}
|
||||||
|
{% endwith %}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if 'normal' != position %}
|
{% if 'normal' != position %}
|
||||||
|
Reference in New Issue
Block a user