Skip to content

Commit 4df2924

Browse files
committed
minor #21315 [DI][FrameworkBundle] Show autowired methods in descriptors (ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI][FrameworkBundle] Show autowired methods in descriptors | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A so we can see the autowired methods using `debug:container`. Commits ------- 482435c501 [DI][FrameworkBundle] Show autowired methods in descriptors
2 parents dcbbb75 + 533ba97 commit 4df2924

Some content is hidden

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

47 files changed

+406
-52
lines changed

Console/Descriptor/JsonDescriptor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,13 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
220220
'lazy' => $definition->isLazy(),
221221
'shared' => $definition->isShared(),
222222
'abstract' => $definition->isAbstract(),
223-
'autowire' => $definition->isAutowired(),
224223
);
225224

225+
$autowiredCalls = array_values(array_filter($definition->getAutowiredCalls(), function ($method) {
226+
return $method !== '__construct';
227+
}));
228+
$data['autowire'] = $definition->isAutowired() ? ($autowiredCalls ?: true) : false;
229+
226230
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
227231
$data['autowiring_types'][] = $autowiringType;
228232
}

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,16 @@ protected function describeContainerDefinition(Definition $definition, array $op
182182
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
183183
."\n".'- Shared: '.($definition->isShared() ? 'yes' : 'no')
184184
."\n".'- Abstract: '.($definition->isAbstract() ? 'yes' : 'no')
185-
."\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no')
186185
;
187186

187+
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
188+
return $method !== '__construct';
189+
});
190+
$output .= "\n".'- Autowire: ';
191+
$output .= $definition->isAutowired() ? ($autowiredCalls ? implode(', ', array_map(function ($method) {
192+
return "`$method`";
193+
}, $autowiredCalls)) : 'yes') : 'no';
194+
188195
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
189196
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
190197
}

Console/Descriptor/TextDescriptor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ protected function describeContainerDefinition(Definition $definition, array $op
295295
$tableRows[] = array('Lazy', $definition->isLazy() ? 'yes' : 'no');
296296
$tableRows[] = array('Shared', $definition->isShared() ? 'yes' : 'no');
297297
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
298-
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
298+
299+
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
300+
return $method !== '__construct';
301+
});
302+
$tableRows[] = array('Autowire', $definition->isAutowired() ? ($autowiredCalls ? implode("\n", $autowiredCalls) : 'yes') : 'no');
299303

300304
if ($autowiringTypes = $definition->getAutowiringTypes(false)) {
301305
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));

Console/Descriptor/XmlDescriptor.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
374374
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
375375
$serviceXML->setAttribute('file', $definition->getFile());
376376

377+
$autowiredCalls = array_filter($definition->getAutowiredCalls(), function ($method) {
378+
return $method !== '__construct';
379+
});
380+
if ($autowiredCalls) {
381+
$serviceXML->appendChild($autowiredMethodsXML = $dom->createElement('autowired-calls'));
382+
foreach ($autowiredCalls as $autowiredMethod) {
383+
$autowiredMethodXML = $dom->createElement('autowired-call');
384+
$autowiredMethodXML->appendChild(new \DOMText($autowiredMethod));
385+
$autowiredMethodsXML->appendChild($autowiredMethodXML);
386+
}
387+
}
388+
377389
$calls = $definition->getMethodCalls();
378390
if (count($calls) > 0) {
379391
$serviceXML->appendChild($callsXML = $dom->createElement('calls'));

Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public static function getContainerDefinitions()
137137
->addTag('tag2')
138138
->addMethodCall('setMailer', array(new Reference('mailer')))
139139
->setFactory(array(new Reference('factory.service'), 'get')),
140+
'definition_autowired' => (new Definition('AutowiredService'))->setAutowired(true),
141+
'definition_autowired_with_methods' => (new Definition('AutowiredService'))
142+
->setAutowiredCalls(array('__construct', 'set*', 'addFoo')),
140143
);
141144
}
142145

Tests/Fixtures/Descriptor/alias_with_definition_1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
- Lazy: yes
1212
- Shared: yes
1313
- Abstract: yes
14-
- Autowired: no
14+
- Autowire: no
1515
- Factory Class: `Full\Qualified\FactoryClass`
1616
- Factory Method: `get`

Tests/Fixtures/Descriptor/alias_with_definition_1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Lazy yes
1515
Shared yes
1616
Abstract yes
17-
Autowired no
17+
Autowire no
1818
Factory Class Full\Qualified\FactoryClass
1919
Factory Method get
2020
---------------- -----------------------------

Tests/Fixtures/Descriptor/alias_with_definition_2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- Lazy: no
1212
- Shared: yes
1313
- Abstract: no
14-
- Autowired: no
14+
- Autowire: no
1515
- File: `/path/to/file`
1616
- Factory Service: `factory.service`
1717
- Factory Method: `get`

Tests/Fixtures/Descriptor/alias_with_definition_2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Lazy no
1818
Shared yes
1919
Abstract no
20-
Autowired no
20+
Autowire no
2121
Required File /path/to/file
2222
Factory Service factory.service
2323
Factory Method get

Tests/Fixtures/Descriptor/builder_1_arguments.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@
8080
"factory_class": "Full\\Qualified\\FactoryClass",
8181
"factory_method": "get",
8282
"tags": []
83+
},
84+
"definition_autowired": {
85+
"class": "AutowiredService",
86+
"public": true,
87+
"synthetic": false,
88+
"lazy": false,
89+
"shared": true,
90+
"abstract": false,
91+
"autowire": true,
92+
"arguments": [],
93+
"file": null,
94+
"tags": []
95+
},
96+
"definition_autowired_with_methods": {
97+
"class": "AutowiredService",
98+
"public": true,
99+
"synthetic": false,
100+
"lazy": false,
101+
"shared": true,
102+
"abstract": false,
103+
"autowire": [
104+
"set*",
105+
"addFoo"
106+
],
107+
"arguments": [],
108+
"file": null,
109+
"tags": []
83110
}
84111
},
85112
"aliases": {

0 commit comments

Comments
 (0)