From 70c42f2676eb82ba2d6137919ddf50b41eaa73ee Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 16 Nov 2016 18:59:59 +0100 Subject: [PATCH 1/3] Cast result to int before adding to it This fixes the occasional warning about non-numeric values when using PHP 7.1 --- .../Loader/XmlFileLoader.php | 23 ++++++++++--------- .../xml/with_key_outside_collection.xml | 9 ++++++++ .../Tests/Loader/XmlFileLoaderTest.php | 9 ++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index e60c2f7df7..b3e4ef4d3e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -346,21 +346,22 @@ class XmlFileLoader extends FileLoader $arg->setAttribute('key', $arg->getAttribute('name')); } - if (!$arg->hasAttribute('key')) { - $key = !$arguments ? 0 : max(array_keys($arguments)) + 1; - } else { - $key = $arg->getAttribute('key'); - } - - // parameter keys are case insensitive - if ('parameter' == $name && $lowercase) { - $key = strtolower($key); - } - // this is used by DefinitionDecorator to overwrite a specific // argument of the parent definition if ($arg->hasAttribute('index')) { $key = 'index_'.$arg->getAttribute('index'); + } elseif (!$arg->hasAttribute('key')) { + // Append an empty argument, then fetch its key to overwrite it later + $arguments[] = null; + $keys = array_keys($arguments); + $key = array_pop($keys); + } else { + $key = $arg->getAttribute('key'); + + // parameter keys are case insensitive + if ('parameter' == $name && $lowercase) { + $key = strtolower($key); + } } switch ($arg->getAttribute('type')) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml new file mode 100644 index 0000000000..5f3a284361 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml @@ -0,0 +1,9 @@ + + + + + foo + bar + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 2de5915f4e..fd45172284 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -542,4 +542,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertSame('Baz', $barConfigurator[0]->getClass()); $this->assertSame('configureBar', $barConfigurator[1]); } + + public function testArgumentWithKeyOutsideCollection() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('with_key_outside_collection.xml'); + + $this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments()); + } } From 4e563aee0232e81667a74884978a123f24e75704 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 6 Dec 2016 21:51:50 +0100 Subject: [PATCH 2/3] fix the docblock in regard to the role argument --- .../Security/Core/Authentication/Token/AbstractToken.php | 2 +- .../Core/Authentication/Token/PreAuthenticatedToken.php | 2 +- .../Core/Authentication/Token/UsernamePasswordToken.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index 7538648b13..2e9c0f34b4 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -33,7 +33,7 @@ abstract class AbstractToken implements TokenInterface /** * Constructor. * - * @param RoleInterface[]|string[] $roles An array of roles + * @param (RoleInterface|string)[] $roles An array of roles * * @throws \InvalidArgumentException */ diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php index b4b5e70b18..a5460f5083 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php @@ -29,7 +29,7 @@ class PreAuthenticatedToken extends AbstractToken * @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 * @param mixed $credentials The user credentials * @param string $providerKey The provider key - * @param RoleInterface[]|string[] $roles An array of roles + * @param (RoleInterface|string)[] $roles An array of roles */ public function __construct($user, $credentials, $providerKey, array $roles = array()) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php index 33b00f01f8..71d19adc14 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php @@ -29,7 +29,7 @@ class UsernamePasswordToken extends AbstractToken * @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method * @param string $credentials This usually is the password of the user * @param string $providerKey The provider key - * @param RoleInterface[]|string[] $roles An array of roles + * @param (RoleInterface|string)[] $roles An array of roles * * @throws \InvalidArgumentException */ From 9218cacf317c0df071b4c338dd4173c63922328d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 8 Dec 2016 14:23:09 +0100 Subject: [PATCH 3/3] [Twig] Fix deprecations with Twig 1.29 --- .../Tests/Translation/TwigExtractorTest.php | 17 ++++++++++++++--- .../Bridge/Twig/Translation/TwigExtractor.php | 12 ++++++++---- src/Symfony/Bundle/TwigBundle/TwigEngine.php | 8 +++++++- .../Resources/views/Profiler/layout.html.twig | 8 +++++--- .../Resources/views/Profiler/toolbar.html.twig | 18 ++++++++++-------- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php index 5e7c4ce521..23869da436 100644 --- a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php @@ -72,8 +72,7 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Twig_Error - * @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/ + * @expectedException \Twig_Error * @dataProvider resourcesWithSyntaxErrorsProvider */ public function testExtractSyntaxError($resources) @@ -82,7 +81,19 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase $twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface'))); $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; + } } /** diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index 950c4d0810..35995dbd64 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -61,10 +61,14 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface try { $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); } catch (\Twig_Error $e) { - if ($file instanceof SplFileInfo) { - $e->setTemplateName($file->getRelativePathname()); - } elseif ($file instanceof \SplFileInfo) { - $e->setTemplateName($file->getRealPath() ?: $file->getPathname()); + if ($file instanceof \SplFileInfo) { + $path = $file->getRealPath() ?: $file->getPathname(); + $name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path; + if (method_exists($e, 'setSourceContext')) { + $e->setSourceContext(new \Twig_Source('', $name, $path)); + } else { + $e->setTemplateName($name); + } } throw $e; diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 0d01648d57..fb4b728a5b 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -74,7 +74,13 @@ class TwigEngine extends BaseEngine implements EngineInterface if ($name instanceof TemplateReference) { try { // 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) { } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig index a3d761deed..37be3ab98d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig @@ -37,9 +37,11 @@