From 1e0d7e4afedf50288782cf5e16acdcbb9b9d90a1 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Sun, 12 Nov 2017 23:24:17 +0100 Subject: [PATCH 01/20] [DependencyInjection] Added support for variadics in named arguments --- .../Compiler/ResolveNamedArgumentsPass.php | 20 +++++++++++++++++++ .../Tests/Fixtures/NamedArgumentsDummy.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index cd6bb6fe8c58a..432768f8f0fef 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -13,6 +13,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper; use Symfony\Component\DependencyInjection\Reference; @@ -81,6 +82,25 @@ protected function processValue($value, $isRoot = false) } } + $lastResolvedArgument = \end($resolvedArguments); + + if (\is_array($lastResolvedArgument) && !empty($lastResolvedArgument)) { + try { + $reflection = $this->getReflectionMethod($value, $method); + $parameters = $reflection->getParameters(); + $lastParam = \end($parameters); + + if ($lastParam->isVariadic()) { + \array_pop($resolvedArguments); + + foreach ($lastResolvedArgument as $argument) { + $resolvedArguments[] = $argument; + } + } + } catch (RuntimeException $runtimeException) { + } + } + if ($resolvedArguments !== $call[1]) { ksort($resolvedArguments); $calls[$i][1] = $resolvedArguments; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php index 09d907dfae769..cd619e2310844 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php @@ -7,7 +7,7 @@ */ class NamedArgumentsDummy { - public function __construct(CaseSensitiveClass $c, $apiKey, $hostName) + public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ...$variadics) { } From 18596507bbdda421fc9133c64ee2de3e190ae5b7 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Sun, 12 Nov 2017 23:24:17 +0100 Subject: [PATCH 02/20] [DependencyInjection] Added support for variadics in named arguments --- .../Compiler/ResolveNamedArgumentsPass.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 432768f8f0fef..9e64358ee827d 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -84,7 +84,10 @@ protected function processValue($value, $isRoot = false) $lastResolvedArgument = \end($resolvedArguments); - if (\is_array($lastResolvedArgument) && !empty($lastResolvedArgument)) { + if (\is_array($lastResolvedArgument) && + !empty($lastResolvedArgument) && + method_exists('ReflectionParameter', 'isVariadic') + ) { try { $reflection = $this->getReflectionMethod($value, $method); $parameters = $reflection->getParameters(); From 31b893549502795095b5245b2497b0a73d4b741a Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 00:01:04 +0100 Subject: [PATCH 03/20] Removed variadic argument from NamedArgumentsDummy --- .../DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php index cd619e2310844..09d907dfae769 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php @@ -7,7 +7,7 @@ */ class NamedArgumentsDummy { - public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ...$variadics) + public function __construct(CaseSensitiveClass $c, $apiKey, $hostName) { } From 625b3d3033c84cd69a84976c430d0d9bbd41f5d4 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 00:01:38 +0100 Subject: [PATCH 04/20] Introduce NamedArgumentsVariadicsDummy to test variadics named arguments. --- .../Tests/Fixtures/NamedArgumentsVariadicsDummy.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php new file mode 100644 index 0000000000000..ea77adbba0746 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php @@ -0,0 +1,13 @@ + Date: Mon, 13 Nov 2017 00:02:28 +0100 Subject: [PATCH 05/20] Test variadics named arguments only on PHP 5.6 and above, also don't use NamedArgumentsDummy to this test. --- .../ResolveNamedArgumentsPassTest.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index fe681b41df788..d39ff76b2c63d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; +use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; /** @@ -152,6 +153,37 @@ public function testResolvePrioritizeNamedOverType() $this->assertEquals(array(new Reference('bar'), 'qwerty', new Reference('foo')), $definition->getArguments()); } + + /** + * @requires PHP 5.6 + */ + public function testVariadics() + { + $container = new ContainerBuilder(); + + $definition = $container->register(NamedArgumentsVariadicsDummy::class, NamedArgumentsVariadicsDummy::class); + $definition->setArguments( + array( + '$variadics' => array( + new Reference('foo'), + new Reference('bar'), + new Reference('baz'), + ), + ) + ); + + $pass = new ResolveNamedArgumentsPass(); + $pass->process($container); + + $this->assertEquals( + array( + 0 => new Reference('foo'), + 1 => new Reference('bar'), + 2 => new Reference('baz'), + ), + $definition->getArguments() + ); + } } class NoConstructor From f0f4c220dfa8e309e725568ed96532e8fc368835 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 00:03:25 +0100 Subject: [PATCH 06/20] Removed blank line. --- .../Tests/Fixtures/NamedArgumentsVariadicsDummy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php index ea77adbba0746..902e80c1bea7d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php @@ -8,6 +8,5 @@ class NamedArgumentsVariadicsDummy { public function __construct(...$variadics) { - } } From 9dbaa094ccf04a46f9c6c7d34de7e7e18cc69532 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 22:14:05 +0100 Subject: [PATCH 07/20] Removed "strict_types". --- .../Tests/Fixtures/NamedArgumentsVariadicsDummy.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php index 902e80c1bea7d..6becca803275a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php @@ -1,7 +1,5 @@ Date: Mon, 13 Nov 2017 22:34:47 +0100 Subject: [PATCH 08/20] Hook into $parameters foreach loop instead of "last argument" enforcing. --- .../Compiler/ResolveNamedArgumentsPass.php | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 9e64358ee827d..6330f01a6fd91 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -53,10 +53,13 @@ protected function processValue($value, $isRoot = false) $parameters = $r->getParameters(); } - if (isset($key[0]) && '$' === $key[0]) { - foreach ($parameters as $j => $p) { - if ($key === '$'.$p->name) { - $resolvedArguments[$j] = $argument; + if (isset($key[0]) && '$' === $key[0]) {foreach ($parameters as $j => $p) { + if ($key === '$'.$p->name) { + if (\PHP_VERSION_ID >= 50600 && $p->isVariadic() && \is_array($argument)) { + foreach ($argument as $variadicArgument) { + $resolvedArguments[$j++] = $variadicArgument; + } + } else {$resolvedArguments[$j] = $argument;} continue 2; } @@ -82,28 +85,6 @@ protected function processValue($value, $isRoot = false) } } - $lastResolvedArgument = \end($resolvedArguments); - - if (\is_array($lastResolvedArgument) && - !empty($lastResolvedArgument) && - method_exists('ReflectionParameter', 'isVariadic') - ) { - try { - $reflection = $this->getReflectionMethod($value, $method); - $parameters = $reflection->getParameters(); - $lastParam = \end($parameters); - - if ($lastParam->isVariadic()) { - \array_pop($resolvedArguments); - - foreach ($lastResolvedArgument as $argument) { - $resolvedArguments[] = $argument; - } - } - } catch (RuntimeException $runtimeException) { - } - } - if ($resolvedArguments !== $call[1]) { ksort($resolvedArguments); $calls[$i][1] = $resolvedArguments; From 28305f261c2123f80843a9a33e99f1affd079a7e Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 22:35:42 +0100 Subject: [PATCH 09/20] Removed unused "use". --- .../DependencyInjection/Compiler/ResolveNamedArgumentsPass.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 6330f01a6fd91..cbf65c66ecbb6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper; use Symfony\Component\DependencyInjection\Reference; From 25cb9bb2415e6fa54e3852f3f3afd0205c093ba6 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Tue, 14 Nov 2017 17:57:00 +0100 Subject: [PATCH 10/20] CS fixes. --- .../Compiler/ResolveNamedArgumentsPass.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index cbf65c66ecbb6..f4bd7bc6a3557 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -52,13 +52,16 @@ protected function processValue($value, $isRoot = false) $parameters = $r->getParameters(); } - if (isset($key[0]) && '$' === $key[0]) {foreach ($parameters as $j => $p) { - if ($key === '$'.$p->name) { - if (\PHP_VERSION_ID >= 50600 && $p->isVariadic() && \is_array($argument)) { - foreach ($argument as $variadicArgument) { - $resolvedArguments[$j++] = $variadicArgument; + if (isset($key[0]) && '$' === $key[0]) { + foreach ($parameters as $j => $p) { + if ($key === '$'.$p->name) { + if (\PHP_VERSION_ID >= 50600 && $p->isVariadic() && \is_array($argument)) { + foreach ($argument as $variadicArgument) { + $resolvedArguments[$j++] = $variadicArgument; + } + } else { + $resolvedArguments[$j] = $argument; } - } else {$resolvedArguments[$j] = $argument;} continue 2; } From 62db7341161f883147ec9c00df19d395cde14625 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Wed, 15 Nov 2017 22:53:42 +0100 Subject: [PATCH 11/20] Do not require PHP 5.6 version. --- .../DependencyInjection/Compiler/ResolveNamedArgumentsPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index f4bd7bc6a3557..2dc53da89a5ec 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -55,7 +55,7 @@ protected function processValue($value, $isRoot = false) if (isset($key[0]) && '$' === $key[0]) { foreach ($parameters as $j => $p) { if ($key === '$'.$p->name) { - if (\PHP_VERSION_ID >= 50600 && $p->isVariadic() && \is_array($argument)) { + if ($p->isVariadic() && \is_array($argument)) { foreach ($argument as $variadicArgument) { $resolvedArguments[$j++] = $variadicArgument; } From 9961ea561b543feffd7dcca990d493583863a3d3 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Sun, 12 Nov 2017 23:24:17 +0100 Subject: [PATCH 12/20] [DependencyInjection] Added support for variadics in named arguments --- .../Compiler/ResolveNamedArgumentsPass.php | 20 +++++++++++++++++++ .../Tests/Fixtures/NamedArgumentsDummy.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 2dc53da89a5ec..e713f1992856e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -13,6 +13,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper; use Symfony\Component\DependencyInjection\Reference; @@ -87,6 +88,25 @@ protected function processValue($value, $isRoot = false) } } + $lastResolvedArgument = \end($resolvedArguments); + + if (\is_array($lastResolvedArgument) && !empty($lastResolvedArgument)) { + try { + $reflection = $this->getReflectionMethod($value, $method); + $parameters = $reflection->getParameters(); + $lastParam = \end($parameters); + + if ($lastParam->isVariadic()) { + \array_pop($resolvedArguments); + + foreach ($lastResolvedArgument as $argument) { + $resolvedArguments[] = $argument; + } + } + } catch (RuntimeException $runtimeException) { + } + } + if ($resolvedArguments !== $call[1]) { ksort($resolvedArguments); $calls[$i][1] = $resolvedArguments; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php index 09d907dfae769..cd619e2310844 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php @@ -7,7 +7,7 @@ */ class NamedArgumentsDummy { - public function __construct(CaseSensitiveClass $c, $apiKey, $hostName) + public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ...$variadics) { } From c849e5ab6376a684aab5e860b5c038afe33712ed Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Sun, 12 Nov 2017 23:24:17 +0100 Subject: [PATCH 13/20] [DependencyInjection] Added support for variadics in named arguments --- .../Compiler/ResolveNamedArgumentsPass.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index e713f1992856e..470fa452405c6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -90,7 +90,10 @@ protected function processValue($value, $isRoot = false) $lastResolvedArgument = \end($resolvedArguments); - if (\is_array($lastResolvedArgument) && !empty($lastResolvedArgument)) { + if (\is_array($lastResolvedArgument) && + !empty($lastResolvedArgument) && + method_exists('ReflectionParameter', 'isVariadic') + ) { try { $reflection = $this->getReflectionMethod($value, $method); $parameters = $reflection->getParameters(); From 44f71c81c42e5740be1186c8a379ee2af4a15082 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 00:01:04 +0100 Subject: [PATCH 14/20] Removed variadic argument from NamedArgumentsDummy --- .../DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php index cd619e2310844..09d907dfae769 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php @@ -7,7 +7,7 @@ */ class NamedArgumentsDummy { - public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ...$variadics) + public function __construct(CaseSensitiveClass $c, $apiKey, $hostName) { } From 8e55fb24dc198342ec5a15270148a738fe285f9c Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Mon, 13 Nov 2017 22:35:42 +0100 Subject: [PATCH 15/20] Removed unused "use". --- .../DependencyInjection/Compiler/ResolveNamedArgumentsPass.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 470fa452405c6..4336891b7772b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper; use Symfony\Component\DependencyInjection\Reference; From 6c0a574855ea9a39d78f4074df28e09eeb35057d Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Tue, 14 Nov 2017 17:57:00 +0100 Subject: [PATCH 16/20] CS fixes. --- .../Compiler/ResolveNamedArgumentsPass.php | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 4336891b7772b..f4bd7bc6a3557 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -55,7 +55,7 @@ protected function processValue($value, $isRoot = false) if (isset($key[0]) && '$' === $key[0]) { foreach ($parameters as $j => $p) { if ($key === '$'.$p->name) { - if ($p->isVariadic() && \is_array($argument)) { + if (\PHP_VERSION_ID >= 50600 && $p->isVariadic() && \is_array($argument)) { foreach ($argument as $variadicArgument) { $resolvedArguments[$j++] = $variadicArgument; } @@ -87,28 +87,6 @@ protected function processValue($value, $isRoot = false) } } - $lastResolvedArgument = \end($resolvedArguments); - - if (\is_array($lastResolvedArgument) && - !empty($lastResolvedArgument) && - method_exists('ReflectionParameter', 'isVariadic') - ) { - try { - $reflection = $this->getReflectionMethod($value, $method); - $parameters = $reflection->getParameters(); - $lastParam = \end($parameters); - - if ($lastParam->isVariadic()) { - \array_pop($resolvedArguments); - - foreach ($lastResolvedArgument as $argument) { - $resolvedArguments[] = $argument; - } - } - } catch (RuntimeException $runtimeException) { - } - } - if ($resolvedArguments !== $call[1]) { ksort($resolvedArguments); $calls[$i][1] = $resolvedArguments; From c749c0c4f82b50cf628359ceeef5dffc1bb5e6a4 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Wed, 15 Nov 2017 22:53:42 +0100 Subject: [PATCH 17/20] Do not require PHP 5.6 version. --- .../DependencyInjection/Compiler/ResolveNamedArgumentsPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index f4bd7bc6a3557..2dc53da89a5ec 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -55,7 +55,7 @@ protected function processValue($value, $isRoot = false) if (isset($key[0]) && '$' === $key[0]) { foreach ($parameters as $j => $p) { if ($key === '$'.$p->name) { - if (\PHP_VERSION_ID >= 50600 && $p->isVariadic() && \is_array($argument)) { + if ($p->isVariadic() && \is_array($argument)) { foreach ($argument as $variadicArgument) { $resolvedArguments[$j++] = $variadicArgument; } From 2e8ebf7535864fa41e0ea0cc127767dc8ce75118 Mon Sep 17 00:00:00 2001 From: pkowalczyk Date: Sun, 19 Nov 2017 12:07:05 +0100 Subject: [PATCH 18/20] Added another constructor parameter to improve test. --- .../Tests/Compiler/ResolveNamedArgumentsPassTest.php | 8 +++++--- .../Tests/Fixtures/NamedArgumentsVariadicsDummy.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index d39ff76b2c63d..d9bc1afb6ce21 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -164,6 +164,7 @@ public function testVariadics() $definition = $container->register(NamedArgumentsVariadicsDummy::class, NamedArgumentsVariadicsDummy::class); $definition->setArguments( array( + '$class' => new \stdClass, '$variadics' => array( new Reference('foo'), new Reference('bar'), @@ -177,9 +178,10 @@ public function testVariadics() $this->assertEquals( array( - 0 => new Reference('foo'), - 1 => new Reference('bar'), - 2 => new Reference('baz'), + 0 => new \stdClass(), + 1 => new Reference('foo'), + 2 => new Reference('bar'), + 3 => new Reference('baz'), ), $definition->getArguments() ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php index 6becca803275a..39a8a8e6b4307 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsVariadicsDummy.php @@ -4,7 +4,7 @@ class NamedArgumentsVariadicsDummy { - public function __construct(...$variadics) + public function __construct(\stdClass $class, ...$variadics) { } } From 86c2db24c0f76b6c1218dc12871eba844148c764 Mon Sep 17 00:00:00 2001 From: pkowalczyk <11366345+PabloKowalczyk@users.noreply.github.com> Date: Sun, 19 Nov 2017 12:36:34 +0100 Subject: [PATCH 19/20] CS fix. --- .../Tests/Compiler/ResolveNamedArgumentsPassTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index d9bc1afb6ce21..89d094d498542 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -164,7 +164,7 @@ public function testVariadics() $definition = $container->register(NamedArgumentsVariadicsDummy::class, NamedArgumentsVariadicsDummy::class); $definition->setArguments( array( - '$class' => new \stdClass, + '$class' => new \stdClass(), '$variadics' => array( new Reference('foo'), new Reference('bar'), From ca5453e870bef5b70b6d4d573f50d8ad43069196 Mon Sep 17 00:00:00 2001 From: pkowalczyk <11366345+PabloKowalczyk@users.noreply.github.com> Date: Mon, 20 Nov 2017 20:56:55 +0100 Subject: [PATCH 20/20] Removed PHP requirement. --- .../Tests/Compiler/ResolveNamedArgumentsPassTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 89d094d498542..4665ee96f5f3a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -154,9 +154,6 @@ public function testResolvePrioritizeNamedOverType() $this->assertEquals(array(new Reference('bar'), 'qwerty', new Reference('foo')), $definition->getArguments()); } - /** - * @requires PHP 5.6 - */ public function testVariadics() { $container = new ContainerBuilder();