Skip to content

Commit c7492c0

Browse files
Merge branch '5.4' into 6.0
* 5.4: Revert "minor #47721 [Notifier] Use local copy of stella-maris/clock when testing (nicolas-grekas)" [Yaml] Minor: Update Inline parse phpdoc [FrameworkBundle] Fix deprecation when accessing a "container.private" service from the test container [DependencyInjection] Fix dumping inlined withers [HttpClient] Move Http clients data collecting at a late level [DependencyInjection] Fix support for named arguments on non-autowired services [FrameworkBundle] restore call to addGlobalIgnoredName Allow EmailValidator 4 Fix detecting mapping with one line annotations
2 parents 6e36593 + 1be9134 commit c7492c0

File tree

8 files changed

+55
-4
lines changed

8 files changed

+55
-4
lines changed

Compiler/ResolveNamedArgumentsPass.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
4343
foreach ($calls as $i => $call) {
4444
[$method, $arguments] = $call;
4545
$parameters = null;
46+
$resolvedKeys = [];
4647
$resolvedArguments = [];
4748

4849
foreach ($arguments as $key => $argument) {
@@ -51,6 +52,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
5152
}
5253

5354
if (\is_int($key)) {
55+
$resolvedKeys[$key] = $key;
5456
$resolvedArguments[$key] = $argument;
5557
continue;
5658
}
@@ -71,9 +73,11 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
7173
if ($key === '$'.$p->name) {
7274
if ($p->isVariadic() && \is_array($argument)) {
7375
foreach ($argument as $variadicArgument) {
76+
$resolvedKeys[$j] = $j;
7477
$resolvedArguments[$j++] = $variadicArgument;
7578
}
7679
} else {
80+
$resolvedKeys[$j] = $p->name;
7781
$resolvedArguments[$j] = $argument;
7882
}
7983

@@ -91,6 +95,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
9195
$typeFound = false;
9296
foreach ($parameters as $j => $p) {
9397
if (!\array_key_exists($j, $resolvedArguments) && ProxyHelper::getTypeHint($r, $p, true) === $key) {
98+
$resolvedKeys[$j] = $p->name;
9499
$resolvedArguments[$j] = $argument;
95100
$typeFound = true;
96101
}
@@ -103,6 +108,12 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
103108

104109
if ($resolvedArguments !== $call[1]) {
105110
ksort($resolvedArguments);
111+
112+
if (!$value->isAutowired() && !array_is_list($resolvedArguments)) {
113+
ksort($resolvedKeys);
114+
$resolvedArguments = array_combine($resolvedKeys, $resolvedArguments);
115+
}
116+
106117
$calls[$i][1] = $resolvedArguments;
107118
}
108119
}

ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ private function createService(Definition $definition, array &$inlineServices, b
10351035
} else {
10361036
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));
10371037

1038-
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs(array_values($arguments));
1038+
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
10391039

10401040
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
10411041
trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name);

Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ private function addServiceMethodCalls(Definition $definition, string $variableN
743743
$witherAssignation = '';
744744

745745
if ($call[2] ?? false) {
746-
if (null !== $sharedNonLazyId && $lastWitherIndex === $k) {
746+
if (null !== $sharedNonLazyId && $lastWitherIndex === $k && 'instance' === $variableName) {
747747
$witherAssignation = sprintf('$this->%s[\'%s\'] = ', $definition->isPublic() ? 'services' : 'privates', $sharedNonLazyId);
748748
}
749749
$witherAssignation .= sprintf('$%s = ', $variableName);

Tests/Compiler/ResolveNamedArgumentsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testInterfaceTypedArgument()
165165
$pass = new ResolveNamedArgumentsPass();
166166
$pass->process($container);
167167

168-
$this->assertSame($expected, $definition->getArgument(3));
168+
$this->assertSame($expected, $definition->getArgument('container'));
169169
}
170170

171171
public function testResolvesMultipleArgumentsOfTheSameType()

Tests/ContainerBuilderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,24 @@ public function testFindTags()
17311731

17321732
$this->assertSame(['tag1', 'tag2', 'tag3'], $container->findTags());
17331733
}
1734+
1735+
/**
1736+
* @requires PHP 8
1737+
*/
1738+
public function testNamedArgument()
1739+
{
1740+
$container = new ContainerBuilder();
1741+
$container->register(E::class)
1742+
->setPublic(true)
1743+
->setArguments(['$second' => 2]);
1744+
1745+
$container->compile();
1746+
1747+
$e = $container->get(E::class);
1748+
1749+
$this->assertSame('', $e->first);
1750+
$this->assertSame(2, $e->second);
1751+
}
17341752
}
17351753

17361754
class FooClass
@@ -1759,3 +1777,15 @@ class C implements X
17591777
class D implements X
17601778
{
17611779
}
1780+
1781+
class E
1782+
{
1783+
public $first;
1784+
public $second;
1785+
1786+
public function __construct($first = '', $second = '')
1787+
{
1788+
$this->first = $first;
1789+
$this->second = $second;
1790+
}
1791+
}

Tests/Dumper/PhpDumperTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,8 @@ public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheSer
13961396
public function testWither()
13971397
{
13981398
$container = new ContainerBuilder();
1399-
$container->register(Foo::class);
1399+
$container->register(Foo::class)
1400+
->setAutowired(true);
14001401

14011402
$container
14021403
->register('wither', Wither::class)

Tests/Fixtures/includes/autowiring_classes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515

1616
class Foo
1717
{
18+
/**
19+
* @required
20+
* @return static
21+
*/
22+
public function cloneFoo()
23+
{
24+
return clone $this;
25+
}
1826
}
1927

2028
class Bar

Tests/Fixtures/php/services_wither.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected function getWitherService()
5353
$instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();
5454

5555
$a = new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo();
56+
$a = $a->cloneFoo();
5657

5758
$instance = $instance->withFoo1($a);
5859
$this->services['wither'] = $instance = $instance->withFoo2($a);

0 commit comments

Comments
 (0)