8000 bug #44979 [DependencyInjection] Add iterable to possible binding typ… · Seldaek/symfony@9f89250 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f89250

Browse files
bug symfony#44979 [DependencyInjection] Add iterable to possible binding type (vladimir.panivko)
This PR was submitted for the 5.4 branch but it was merged into the 4.4 branch instead. Discussion ---------- [DependencyInjection] Add iterable to possible binding type | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT When iterable type is set in binding like in example https://symfony.com/doc/current/service_container.html#binding-arguments-by-name-or-type, system tries to autoload class iterable here src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php:137 ``` if (is_subclass_of($m[1], \UnitEnum::class)) { ``` Commits ------- f9f78c7 ResolveBindingsPass remove loading of class iterable
2 parents c7a5902 + f9f78c7 commit 9f89250

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected function processValue($value, $isRoot = false)
125125
$this->unusedBindings[$bindingId] = [$key, $this->currentId, $bindingType, $file];
126126
}
127127

128-
if (preg_match('/^(?:(?:array|bool|float|int|string|([^ $]++)) )\$/', $key, $m)) {
128+
if (preg_match('/^(?:(?:array|bool|float|int|string|iterable|([^ $]++)) )\$/', $key, $m)) {
129129
$bindingNames[substr($key, \strlen($m[0]))] = $binding;
130130
}
131131

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
2828
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
2929
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedEnumArgumentDummy;
30+
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedIterableArgumentDummy;
3031
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
3132
use Symfony\Component\DependencyInjection\TypedReference;
3233

@@ -209,4 +210,17 @@ public function testEmptyBindingTypehint()
209210
$pass = new ResolveBindingsPass();
210211
$pass->process($container);
211212
}
213+
8000 214+
public function testIterableBindingTypehint()
215+
{
216+
$container = new ContainerBuilder();
217+
$definition = $container->register('bar', NamedIterableArgumentDummy::class);
218+
$definition->setBindings([
219+
'iterable $items' => new TaggedIteratorArgument('foo'),
220+
]);
221+
$pass = new ResolveBindingsPass();
222+
$pass->process($container);
223+
224+
$this->assertInstanceOf(TaggedIteratorArgument::class, $container->getDefinition('bar')->getArgument(0));
225+
}
212226
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
class NamedIterableArgumentDummy
15+
{
16+
public function __construct(iterable $items)
17+
{
18+
}
19+
}

0 commit comments

Comments
 (0)
0