8000 [DependencyInjection] Fix support for inner collections when using `<… · symfony/symfony@4634eeb · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4634eeb

Browse files
zerustechnicolas-grekas
authored andcommitted
[DependencyInjection] Fix support for inner collections when using <bind>
1 parent 20ee89c commit 4634eeb

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275

276276
<xsd:complexType name="bind" mixed="true">
277277
<xsd:choice maxOccurs="unbounded">
278-
<xsd:element name="bind" type="argument" minOccurs="0" maxOccurs="unbounded" />
278+
<xsd:element name="bind" type="bind_argument" minOccurs="0" maxOccurs="unbounded" />
279279
<xsd:element name="service" type="service" />
280280
</xsd:choice>
281281
<xsd:attribute name="type" type="argument_type" />
@@ -286,6 +286,24 @@
286286
<xsd:attribute name="tag" type="xsd:string" />
287287
</xsd:complexType>
288288

289+
<xsd:complexType name="bind_argument" mixed="true">
290+
<xsd:choice minOccurs="0">
291+
<xsd:element name="bind" type="bind_argument" maxOccurs="unbounded" />
292+
<xsd:element name="service" type="service" />
293+
<xsd:element name="exclude" type="xsd:string" maxOccurs="unbounded" />
294+
</xsd:choice>
295+
<xsd:attribute name="type" type="argument_type" />
296+
<xsd:attribute name="id" type="xsd:string" />
297+
<xsd:attribute name="key" type="xsd:string" />
298+
<xsd:attribute name="index" type="xsd:integer" />
299+
<xsd:attribute name="on-invalid" type="invalid_sequence" />
300+
<xsd:attribute name="tag" type="xsd:string" />
301+
<xsd:attribute name="index-by" type="xsd:string" />
302+
<xsd:attribute name="default-index-method" type="xsd:string" />
303+
<xsd:attribute name="default-priority-method" type="xsd:string" />
304+
<xsd:attribute name="< 8000 /span>exclude" type="xsd:string" />
305+
</xsd:complexType>
306+
289307
<xsd:complexType name="argument" mixed="true">
290308
<xsd:choice minOccurs="0">
291309
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="bar1" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
5+
<bind key="$foo" type="collection">
6+
<bind>item.1</bind>
7+
<bind>item.2</bind>
8+
</bind>
9+
</service>
10+
<service id="bar2" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
11+
<bind key="$foo" type="collection">
12+
<bind>item.1</bind>
13+
<bind>item.2</bind>
14+
</bind>
15+
</service>
16+
<service id="bar3" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
17+
<bind key="$foo" type="collection">
18+
<bind>item.1</bind>
19+
<bind>item.2</bind>
20+
<bind>item.3</bind>
21+
<bind>item.4</bind>
22+
</bind>
23+
</service>
24+
<service id="bar4" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
25+
<bind key="$foo" type="collection">
26+
<bind>item.1</bind>
27+
<bind>item.2</bind>
28+
<bind key="1">item.3</bind>
29+
<bind>item.4</bind>
30+
</bind>
31+
</service>
32+
<service id="bar5" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
33+
<bind key="$foo" type="collection">
34+
<bind>item.1</bind>
35+
<bind>item.2</bind>
36+
<bind type="collection">
37+
<bind>item.3.1</bind>
38+
<bind>item.3.2</bind>
39+
</bind>
40+
</bind>
41+
</service>
42+
<service id="bar6" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
43+
<bind key="$foo" type="collection">
44+
<bind>item.1</bind>
45+
<bind type="collection">
46+
<bind>item.2.1</bind>
47+
<bind>item.2.2</bind>
48+
</bind>
49+
<bind>item.3</bind>
50+
</bind>
51+
</service>
52+
<service id="bar7" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
53+
<bind key="$foo" type="iterator">
54+
<bind>item.1</bind>
55+
<bind>item.2</bind>
56+
</bind>
57+
</service>
58+
<service id="bar8" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar" autowire="true">
59+
<bind key="$foo" type="iterator">
60+
<bind>item.1</bind>
61+
<bind>item.2</bind>
62+
<bind type="collection">
63+
<bind>item.3.1</bind>
64+
<bind>item.3.2</bind>
65+
</bind>
66+
</bind>
67+
</service>
68+
</services>
69+
</container>

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,4 +1166,32 @@ public function testClosure()
11661166
$definition = $container->getDefinition('closure_property')->getProperties()['foo'];
11671167
$this->assertEquals((new Definition('Closure'))->setFactory(['Closure', 'fromCallable'])->addArgument(new Reference('bar')), $definition);
11681168
}
1169+
1170+
/**
1171+
* @dataProvider dataForBindingsAndInnerCollections
1172+
*/
1173+
public function testBindingsAndInnerCollections($bindName, $expected)
1174+
{
1175+
$container = new ContainerBuilder();
1176+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
1177+
$loader->load('bindings_and_inner_collections.xml');
1178+
(new ResolveBindingsPass())->process($container);
1179+
$definition = $container->getDefinition($bindName);
1180+
$actual = $definition->getBindings()['$foo']->getValues()[0];
1181+
$this->assertEquals($actual, $expected);
1182+
}
1183+
1184+
public function dataForBindingsAndInnerCollections()
1185+
{
1186+
return [
1187+
['bar1', ['item.1', 'item.2']],
1188+
['bar2', ['item.1', 'item.2']],
1189+
['bar3', ['item.1', 'item.2', 'item.3', 'item.4']],
1190+
['bar4', ['item.1', 'item.3', 'item.4']],
1191+
['bar5', ['item.1', 'item.2', ['item.3.1', 'item.3.2']]],
1192+
['bar6', ['item.1', ['item.2.1', 'item.2.2'], 'item.3']],
1193+
['bar7', new IteratorArgument(['item.1', 'item.2'])],
1194+
['bar8', new IteratorArgument(['item.1', 'item.2', ['item.3.1', 'item.3.2']])],
1195+
];
1196+
}
11691197
}

0 commit comments

Comments
 (0)
0