Skip to content

Commit c74d45e

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 9de0309 + 6cf9bdb commit c74d45e

32 files changed

+156
-82
lines changed

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)) {

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
}

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
}

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) {

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": {

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

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"/>

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": {

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`

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">

0 commit comments

Comments
 (0)