Skip to content

Commit fe239df

Browse files
[DependencyInjection] Fix binding "iterable $foo" when using the PHP-DSL
1 parent 3ef7a34 commit fe239df

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

Compiler/ResolveBindingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function processValue($value, $isRoot = false)
134134
}
135135

136136
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
137-
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, "%s", "%s", "%s" or ServiceLocatorArgument, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue)));
137+
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected "%s", "%s", "%s", "%s" or null, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, ServiceLocatorArgument::class, \gettype($bindingValue)));
138138
}
139139
}
140140

Loader/Configurator/Traits/BindTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ trait BindTrait
3434
final public function bind(string $nameOrFqcn, $valueOrRef): self
3535
{
3636
$valueOrRef = static::processValue($valueOrRef, true);
37-
if (!preg_match('/^(?:(?:array|bool|float|int|string)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {
37+
if (!preg_match('/^(?:(?:array|bool|float|int|string|iterable)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {
3838
throw new InvalidArgumentException(sprintf('Invalid binding for service "%s": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "%s".', $this->id, $nameOrFqcn));
3939
}
4040
$bindings = $this->definition->getBindings();

Tests/Fixtures/Prototype/Foo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Foo implements FooInterface, Sub\BarInterface
66
{
7-
public function __construct($bar = null)
7+
public function __construct($bar = null, iterable $foo)
88
{
99
}
1010

Tests/Fixtures/config/defaults.expected.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ services:
1515
- { name: t, a: b }
1616
autowire: true
1717
autoconfigure: true
18-
arguments: ['@bar']
18+
arguments: ['@bar', !tagged_iterator foo]
1919
bar:
2020
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
2121
public: true
2222
tags:
2323
- { name: t, a: b }
2424
autowire: true
25+
arguments: [null, !tagged_iterator foo]
2526
calls:
2627
- [setFoo, ['@bar']]
2728

Tests/Fixtures/config/defaults.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
->autowire()
1515
->tag('t', ['a' => 'b'])
1616
->bind(Foo::class, ref('bar'))
17+
->bind('iterable $foo', tagged_iterator('foo'))
1718
->public();
1819

1920
$s->set(Foo::class)->args([ref('bar')])->public();

0 commit comments

Comments
 (0)