Skip to content

Commit 482435c

Browse files
committed
[DI][FrameworkBundle] Show autowired methods in descriptors
1 parent b5d9b3b commit 482435c

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

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

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

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

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

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

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

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

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public static function getContainerDefinitions()
132132
->addTag('tag2')
133133
->addMethodCall('setMailer', array(new Reference('mailer')))
134134
->setFactory(array(new Reference('factory.service'), 'get')),
135+
'definition_autowired' => (new Definition('AutowiredService'))->setAutowired(true),
136+
'definition_autowired_with_methods' => (new Definition('AutowiredService'))
137+
->setAutowiredCalls(array('__construct', 'set*', 'addFoo')),
135138
);
136139
}
137140

src/Symfony/Bundle/FrameworkBundle/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`

src/Symfony/Bundle/FrameworkBundle/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
---------------- -----------------------------

src/Symfony/Bundle/FrameworkBundle/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`

src/Symfony/Bundle/FrameworkBundle/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

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@
7070
"factory_class": "Full\\Qualified\\FactoryClass",
7171
"factory_method": "get",
7272
"tags": []
73+
},
74+
"definition_autowired": {
75+
"class": "AutowiredService",
76+
"public": true,
77+
"synthetic": false,
78+
"lazy": false,
79+
"shared": true,
80+
"abstract": false,
81+
"autowire": true,
82+
"arguments": [],
83+
"file": null,
84+
"tags": []
85+
},
86+
"definition_autowired_with_methods": {
87+
"class": "AutowiredService",
88+
"public": true,
89+
"synthetic": false,
90+
"lazy": false,
91+
"shared": true,
92+
"abstract": false,
93+
"autowire": [
94+
"set*",
95+
"addFoo"
96+
],
97+
"arguments": [],
98+
"file": null,
99+
"tags": []
73100
}
74101
},
75102
"aliases": {

0 commit comments

Comments
 (0)