8000 bug #16469 [DependencyInjection] [FrameworkBundle] Enhance autowiring… · symfony/symfony@515007e · GitHub
[go: up one dir, main page]

Skip to content

Commit 515007e

Browse files
committed
bug #16469 [DependencyInjection] [FrameworkBundle] Enhance autowiring DX (dunglas)
This PR was merged into the 2.8 branch. Discussion ---------- [DependencyInjection] [FrameworkBundle] Enhance autowiring DX | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a * Dump autowiring data when using the container * Add autowiring data to the `debug:container` command Commits ------- 9c3b910 [FrameworkBundle] Autowiring support for debug:container 18913e1 [DependencyInjection] Add autowiring support to dumpers
2 parents 0e66da8 + 9c3b910 commit 515007e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+287
-82
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
228228
}
229229

230230
$data['abstract'] = $definition->isAbstract();
231+
232+
if (method_exists($definition, 'isAutowired')) {
233+
$data['autowire'] = $definition->isAutowired();
234+
235+
$data['autowiring_types'] = array();
236+
foreach ($definition->getAutowiringTypes() as $autowiringType) {
237+
$data['autowiring_types'][] = $autowiringType;
238+
}
239+
}
240+
231241
$data['file'] = $definition->getFile();
232242

233243
if ($definition->getFactoryClass(false)) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ protected function describeContainerDefinition(Definition $definition, array $op
195195

196196
$output .= "\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no');
197197

198+
if (method_exists($definition, 'isAutowired')) {
199+
$output .= "\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no');
200+
201+
foreach ($definition->getAutowiringTypes() as $autowiringType) {
202+
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
203+
}
204+
}
205+
198206
if ($definition->getFile()) {
199207
$output .= "\n".'- File: `'.$definition->getFile().'`';
200208
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ protected function describeContainerDefinition(Definition $definition, array $op
288288
}
289289
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
290290

291+
if (method_exists($definition, 'isAutowired')) {
292+
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
293+
294+
$autowiringTypes = $definition->getAutowiringTypes();
295+
if (count($autowiringTypes)) {
296+
$autowiringTypesInformation = implode(', ', $autowiringTypes);
297+
} else {
298+
$autowiringTypesInformation = '-';
299+
}
300+
301+
$tableRows[] = array('Autowiring Types', $autowiringTypesInformation);
302+
}
303+
291304
if ($definition->getFile()) {
292305
$tableRows[] = array('Required File', $definition->getFile() ? $definition->getFile() : '-');
293306
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
373373
$serviceXML->setAttribute('synchronized', $definition->isSynchronized(false) ? 'true' : 'false');
374374
}
375375
$serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
376+
377+
if (method_exists($definition, 'isAutowired')) {
378+
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
379+
}
380+
376381
$serviceXML->setAttribute('file', $definition->getFile());
377382

378383
if (!$omitTags) {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"factory_method": "get",
1515
"tags": [
1616

17-
]
17+
],
18+
"autowire": false,
19+
"autowiring_types": []
1820
}
1921
},
2022
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ definition_1
1515
- Shared: yes
1616
- Synchronized: no
1717
- Abstract: yes
18+
- Autowired: no
1819
- Factory Class: `Full\Qualified\FactoryClass`
1920
- Factory Method: `get`
2021

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<container>
33
<alias id="alias_1" service="service_1" public="true"/>
44
<alias id="alias_2" service="service_2" public="false"/>
5-
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" file="">
5+
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" autowired="false" file="">
66
<factory class="Full\Qualified\FactoryClass" method="get"/>
77
</definition>
88
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"factory_method": "get",
1515
"tags": [
1616

17-
]
17+
],
18+
"autowire": false,
19+
"autowiring_types": []
1820
},
1921
"definition_2": {
2022
"class": "Full\\Qualified\\Class2",
@@ -48,7 +50,9 @@
4850

4951
]
5052
}
51-
]
53+
],
54+
"autowire": false,
55+
"autowiring_types": []
5256
}
5357
},
5458
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ definition_1
1515
- Shared: yes
1616
- Synchronized: no
1717
- Abstract: yes
18+
- Autowired: no
1819
- Factory Class: `Full\Qualified\FactoryClass`
1920
- Factory Method: `get`
2021
@@ -29,6 +30,7 @@ definition_2
2930
- Shared: yes
3031
- Synchronized: no
3132
- Abstract: no
33+
- Autowired: no
3234
- File: `/path/to/file`
3335
- Factory Service: `factory.service`
3436
- Factory Method: `get`

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<container>
33
<alias id="alias_1" service="service_1" public="true"/>
44
<alias id="alias_2" service="service_2" public="false"/>
5-
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" file="">
5+
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" autowired="false" file="">
66
<factory class="Full\Qualified\FactoryClass" method="get"/>
77
</definition>
8-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
8+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" autowired="false" file="/path/to/file">
99
<factory service="factory.service" method="get"/>
1010
<tags>
1111
<tag name="tag1">

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
]
3434
}
35-
]
35+
],
36+
"autowire": false,
37+
"autowiring_types": []
3638
}
3739
},
3840
"aliases": [

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ definition_2
1515
- Shared: yes
1616
- Synchronized: no
1717
- Abstract: no
18+
- Autowired: no
1819
- File: `/path/to/file`
1920
- Factory Service: `factory.service`
2021
- Factory Method: `get`

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
3-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
3+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" autowired="false" file="/path/to/file">
44
<factory service="factory.service" method="get"/>
55
<tags>
66
<tag name="tag1">

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"abstract": false,
1212
"file": "\/path\/to\/file",
1313
"factory_service": "factory.service",
14-
"factory_method": "get"
14+
"factory_method": "get",
15+
"autowire": false,
16+
"autowiring_types": []
1517
}
1618
],
1719
"tag2": [
@@ -26,7 +28,9 @@
2628
"abstract": false,
2729
"file": "\/path\/to\/file",
2830
"factory_service": "factory.service",
29-
"factory_method": "get"
31+
"factory_method": "get",
32+
"autowire": false,
33+
"autowiring_types": []
3034
}
3135
]
3236
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ definition_2
1515
- Shared: yes
1616
- Synchronized: no
1717
- Abstract: no
18+
- Autowired: no
1819
- File: `/path/to/file`
1920
- Factory Service: `factory.service`
2021
- Factory Method: `get`
@@ -34,6 +35,7 @@ definition_2
3435
- Shared: yes
3536
- Synchronized: no
3637
- Abstract: no
38+
- Autowired: no
3739
- File: `/path/to/file`
3840
- Factory Service: `factory.service`
3941
- Factory Method: `get`

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
33
<tag name="tag1">
4-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
4+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" autowired="false" file="/path/to/file">
55
<factory service="factory.service" method="get"/>
66
</definition>
77
</tag>
88
<tag name="tag2">
9-
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
9+
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" autowired="false" file="/path/to/file">
1010
<factory service="factory.service" method="get"/>
1111
</definition>
1212
</tag>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
"factory_method": "get",
1313
"tags": [
1414

15-
]
15+
],
16+
"autowire": false,
17+
"autowiring_types": []
1618
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
- Shared: yes
77
- Synchronized: no
88
- Abstract: yes
9+
- Autowired: no
910
- Factory Class: `Full\Qualified\FactoryClass`
1011
- Factory Method: `get`
Lines changed: 17 additions & 15 deletions
6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
---------------- -----------------------------
2-
Option Value
3-
---------------- -----------------------------
4-
Service ID -
5-
Class Full\Qualified\Class1
-
Tags -
7-
Scope container
8-
Public yes
9-
Synthetic no
10-
Lazy yes
11-
Synchronized no
12-
Abstract yes
13-
Factory Class Full\Qualified\FactoryClass
14-
Factory Method get
15-
---------------- -----------------------------
1+
------------------ -----------------------------
2+
Option Value
3+
------------------ -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class1
6+
Tags -
7+
Scope container
8+
Public yes
9+
Synthetic no
10+
Lazy yes
11+
Synchronized no
12+
Abstract yes
13+
Autowired no
14+
Autowiring Types -
15+
Factory Class Full\Qualified\FactoryClass
16+
Factory Method get
17+
------------------ -----------------------------
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" file="">
2+
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="false" abstract="true" autowired="false" file="">
33
<factory class="Full\Qualified\FactoryClass" method="get"/>
44
</definition>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@
3030

3131
]
3232
}
33-
]
33+
],
34+
"autowire": false,
35+
"autowiring_types": []
3436
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Shared: yes
77
- Synchronized: no
88
- Abstract: no
9+
- Autowired: no
910
- File: `/path/to/file`
1011
- Factory Service: `factory.service`
1112
- Factory Method: `get`
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
----------------- -------------------------------------------------------
2-
Option Value
3-
----------------- -------------------------------------------------------
4-
Service ID -
5-
Class Full\Qualified\Class2
6-
Tags tag1 (attr1: val1, attr2: val2)tag1 (attr3: val3)tag2
7-
Scope container
8-
Public no
9-
Synthetic yes
10-
Lazy no
11-
Synchronized no
12-
Abstract no
13-
Required File /path/to/file
14-
Factory Service factory.service
15-
Factory Method get
16-
----------------- -------------------------------------------------------
1+
------------------ -------------------------------------------------------
2+
Option Value
3+
------------------ -------------------------------------------------------
4+
Service ID -
5+
Class Full\Qualified\Class2
6+
Tags tag1 (attr1: val1, attr2: val2)tag1 (attr3: val3)tag2
7+
Scope container
8+
Public no
9+
Synthetic yes
10+
Lazy no
11+
Synchronized no
12+
Abstract no
13+
Autowired no
14+
Autowiring Types -
15+
Required File /path/to/file
16+
Factory Service factory.service
17+
Factory Method get
18+
------------------ -------------------------------------------------------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<definition class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" file="/path/to/file">
2+
<definition class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" synchronized="false" abstract="false" autowired="false" file="/path/to/file">
33
<factory service="factory.service" method="get"/>
44
<tags>
55
<tag name="tag1">

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
"factory_method": "get",
1313
"tags": [
1414

15-
]
15+
],
16+
"autowire": false,
17+
"autowiring_types": []
1618
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
- Shared: yes
77
- Synchronized: yes
88
- Abstract: yes
9+
- Autowired: no
910
- Factory Class: `Full\Qualified\FactoryClass`
1011
- Factory Method: `get`
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
---------------- -----------------------------
2-
Option Value
3-
---------------- -----------------------------
4-
Service ID -
5-
Class Full\Qualified\Class1
6-
Tags -
7-
Scope container
8-
Public yes
9-
Synthetic no
10-
Lazy yes
11-
Synchronized yes
12-
Abstract yes
13-
Factory Class Full\Qualified\FactoryClass
14-
Factory Method get
15-
---------------- -----------------------------
1+
------------------ -----------------------------
2+
Option Value
3+
------------------ -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class1
6+
Tags -
7+
Scope container
8+
Public yes
9+
Synthetic no
10+
Lazy yes
11+
Synchronized yes
12+
Abstract yes
13+
Autowired no
14+
Autowiring Types -
15+
Factory Class Full\Qualified\FactoryClass
16+
Factory Method get
17+
------------------ -----------------------------
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<definition class="Full\Qualified\Class1" factory-class="Full\Qualified\FactoryClass" factory-method="get" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="true" abstract="true" file=""/>
2+
<definition class="Full\Qualified\Class1" factory-class="Full\Qualified\FactoryClass" factory-method="get" scope="container" public="true" synthetic="false" lazy="true" shared="true" synchronized="true" abstract="true" autowired="false" file=""/>

0 commit comments

Comments
 (0)
0