Skip to content

Commit 80c6d9e

Browse files
Merge branch '3.4' into 4.3
* 3.4: [DI] fix locators with numeric keys
2 parents b9cec89 + 0ea4d39 commit 80c6d9e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Compiler/ServiceLocatorTagPass.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ protected function processValue($value, $isRoot = false)
5252
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set.', $this->currentId));
5353
}
5454

55+
$i = 0;
56+
5557
foreach ($arguments[0] as $k => $v) {
5658
if ($v instanceof ServiceClosureArgument) {
5759
continue;
@@ -60,10 +62,13 @@ protected function processValue($value, $isRoot = false)
6062
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, \is_object($v) ? \get_class($v) : \gettype($v), $k));
6163
}
6264

63-
if (\is_int($k)) {
65+
if ($i === $k) {
6466
unset($arguments[0][$k]);
6567

6668
$k = (string) $v;
69+
++$i;
70+
} elseif (\is_int($k)) {
71+
$i = null;
6772
}
6873
$arguments[0][$k] = new ServiceClosureArgument($v);
6974
}

Tests/Compiler/ServiceLocatorTagPassTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function testInheritedKeyOverwritesPreviousServiceWithKey()
114114
->setArguments([[
115115
'bar' => new Reference('baz'),
116116
new Reference('bar'),
117+
16 => new Reference('baz'),
117118
]])
118119
->addTag('container.service_locator')
119120
;
@@ -124,6 +125,7 @@ public function testInheritedKeyOverwritesPreviousServiceWithKey()
124125
$locator = $container->get('foo');
125126

126127
$this->assertSame(TestDefinition1::class, \get_class($locator('bar')));
128+
$this->assertSame(TestDefinition2::class, \get_class($locator(16)));
127129
}
128130

129131
public function testBindingsAreCopied()

0 commit comments

Comments
 (0)