Skip to content

Commit 7f633d1

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Twig] Fix deprecations with Twig 1.29 fix the docblock in regard to the role argument Cast result to int before adding to it
2 parents 62839f7 + 28a0be8 commit 7f633d1

File tree

11 files changed

+78
-34
lines changed

11 files changed

+78
-34
lines changed

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function getExtractData()
7272
}
7373

7474
/**
75-
* @expectedException \Twig_Error
76-
* @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
75+
* @expectedException \Twig_Error
7776
* @dataProvider resourcesWithSyntaxErrorsProvider
7877
*/
7978
public function testExtractSyntaxError($resources)
@@ -82,7 +81,19 @@ public function testExtractSyntaxError($resources)
8281
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
8382

8483
$extractor = new TwigExtractor($twig);
85-
$extractor->extract($resources, new MessageCatalogue('en'));
84+
85+
try {
86+
$extractor->extract($resources, new MessageCatalogue('en'));
87+
} catch (\Twig_Error $e) {
88+
if (method_exists($e, 'getSourceContext')) {
89+
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
90+
$this->assertSame(1, $e->getLine());
91+
$this->assertSame('Unclosed "block".', $e->getMessage());
92+
} else {
93+
$this->expectExceptionMessageRegExp('/Unclosed "block" in ".*extractor(\\/|\\\\)syntax_error\\.twig" at line 1/');
94+
}
95+
throw $e;
96+
}
8697
}
8798

8899
/**

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ public function extract($resource, MessageCatalogue $catalogue)
6161
try {
6262
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6363
} catch (\Twig_Error $e) {
64-
if ($file instanceof SplFileInfo) {
65-
$e->setTemplateName($file->getRelativePathname());
66-
} elseif ($file instanceof \SplFileInfo) {
67-
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
64+
if ($file instanceof \SplFileInfo) {
65+
$path = $file->getRealPath() ?: $file->getPathname();
66+
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
67+
if (method_exists($e, 'setSourceContext')) {
68+
$e->setSourceContext(new \Twig_Source('', $name, $path));
69+
} else {
70+
$e->setTemplateName($name);
71+
}
6872
}
6973

7074
throw $e;

src/Symfony/Bundle/TwigBundle/TwigEngine.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public function render($name, array $parameters = array())
7474
if ($name instanceof TemplateReference) {
7575
try {
7676
// try to get the real name of the template where the error occurred
77-
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
77+
$name = $e->getTemplateName();
78+
$path = (string) $this->locator->locate($this->parser->parse($name));
79+
if (method_exists($e, 'setSourceContext')) {
80+
$e->setSourceContext(new \Twig_Source('', $name, $path));
81+
} else {
82+
$e->setTemplateName($path);
83+
}
7884
} catch (\Exception $e2) {
7985
}
8086
}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@
7272
<ul id="menu-profiler">
7373
{% for name, template in templates %}
7474
{% set menu -%}
75-
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
76-
{{- block('menu', template) -}}
77-
{% endwith %}
75+
{% if block('menu', template) is defined %}
76+
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
77+
{{- block('menu', template) -}}
78+
{% endwith %}
79+
{% endif %}
7880
{%- endset %}
7981
{% if menu is not empty %}
8082
<li class="{{ name }} {{ name == panel ? 'selected' : '' }}">

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626

2727
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
2828
{% for name, template in templates %}
29-
{% with {
30-
collector: profile.getcollector(name),
31-
profiler_url: profiler_url,
32-
token: profile.token,
33-
name: name,
34-
profiler_markup_version: profiler_markup_version
35-
} %}
36-
{{ block('toolbar', template) }}
37-
{% endwith %}
29+
{% if block('toolbar', template) is defined %}
30+
{% with {
31+
collector: profile.getcollector(name),
32+
profiler_url: profiler_url,
33+
token: profile.token,
34+
name: name,
35+
profiler_markup_version: profiler_markup_version
36+
} %}
37+
{{ block('toolbar', template) }}
38+
{% endwith %}
39+
{% endif %}
3840
{% endfor %}
3941

4042
{% if 'normal' != position %}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,22 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
369369
$arg->setAttribute('key', $arg->getAttribute('name'));
370370
}
371371

372-
if (!$arg->hasAttribute('key')) {
373-
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
374-
} else {
375-
$key = $arg->getAttribute('key');
376-
}
377-
378-
// parameter keys are case insensitive
379-
if ('parameter' == $name && $lowercase) {
380-
$key = strtolower($key);
381-
}
382-
383372
// this is used by DefinitionDecorator to overwrite a specific
384373
// argument of the parent definition
385374
if ($arg->hasAttribute('index')) {
386375
$key = 'index_'.$arg->getAttribute('index');
376+
} elseif (!$arg->hasAttribute('key')) {
377+
// Append an empty argument, then fetch its key to overwrite it later
378+
$arguments[] = null;
379+
$keys = array_keys($arguments);
380+
$key = array_pop($keys);
381+
} else {
382+
$key = $arg->getAttribute('key');
383+
384+
// parameter keys are case insensitive
385+
if ('parameter' == $name && $lowercase) {
386+
$key = strtolower($key);
387+
}
387388
}
388389

389390
switch ($arg->getAttribute('type')) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="foo" class="Foo">
5+
<argument key="type">foo</argument>
6+
<argument>bar</argument>
7+
</service>
8+
</services>
9+
</container>

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,13 @@ public function testAutowire()
577577

578578
$this->assertTrue($container->getDefinition('bar')->isAutowired());
579579
}
580+
581+
public function testArgumentWithKeyOutsideCollection()
582+
{
583+
$container = new ContainerBuilder();
584+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
585+
$loader->load('with_key_outside_collection.xml');
586+
587+
$this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments());
588+
}
580589
}

src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class AbstractToken implements TokenInterface
3333
/**
3434
* Constructor.
3535
*
36-
* @param RoleInterface[]|string[] $roles An array of roles
36+
* @param (RoleInterface|string)[] $roles An array of roles
3737
*
3838
* @throws \InvalidArgumentException
3939
*/

src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PreAuthenticatedToken extends AbstractToken
2929
* @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string
3030
* @param mixed $credentials The user credentials
3131
* @param string $providerKey The provider key
32-
* @param RoleInterface[]|string[] $roles An array of roles
32+
* @param (RoleInterface|string)[] $roles An array of roles
3333
*/
3434
public function __construct($user, $credentials, $providerKey, array $roles = array())
3535
{

0 commit comments

Comments
 (0)