Skip to content

Commit 151fe5a

Browse files
committed
feature #18416 [FrameworkBundle] Calls support for debug:container (JhonnyL)
This PR was merged into the 3.1-dev branch. Discussion ---------- [FrameworkBundle] Calls support for debug:container | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | | License | MIT | Doc PR | * Show methods to be called after service initialization in `debug:container` command Commits ------- b2d1038 [FrameworkBundle] Calls support for debug:container
2 parents 436b36e + 3c6291e commit 151fe5a

18 files changed

+69
-1
lines changed

Console/Descriptor/JsonDescriptor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
242242
}
243243
}
244244

245+
$calls = $definition->getMethodCalls();
246+
if (count($calls) > 0) {
247+
$data['calls'] = array();
248+
foreach ($calls as $callData) {
249+
$data['calls'][] = $callData[0];
250+
}
251+
}
252+
245253
if (!$omitTags) {
246254
$data['tags'] = array();
247255
if (count($definition->getTags())) {

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ protected function describeContainerDefinition(Definition $definition, array $op
214214
}
215215
}
216216

217+
$calls = $definition->getMethodCalls();
218+
foreach ($calls as $callData) {
219+
$output .= "\n".'- Call: `'.$callData[0].'`';
220+
}
221+
217222
if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
218223
foreach ($definition->getTags() as $tagName => $tagData) {
219224
foreach ($tagData as $parameters) {

Console/Descriptor/TextDescriptor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ protected function describeContainerDefinition(Definition $definition, array $op
275275
}
276276
$tableRows[] = array('Tags', $tagInformation);
277277

278+
$calls = $definition->getMethodCalls();
279+
if (count($calls) > 0) {
280+
$callInformation = [];
281+
foreach ($calls as $call) {
282+
$callInformation[] = $call[0];
283+
}
284+
$tableRows[] = array('Calls', implode(', ', $callInformation));
285+
}
286+
278287
$tableRows[] = array('Public', $definition->isPublic() ? 'yes' : 'no');
279288
$tableRows[] = array('Synthetic', $definition->isSynthetic() ? 'yes' : 'no');
280289
$tableRows[] = array('Lazy', $definition->isLazy() ? 'yes' : 'no');

Console/Descriptor/XmlDescriptor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu
360360

361361
$serviceXML->setAttribute('file', $definition->getFile());
362362

363+
$calls = $definition->getMethodCalls();
364+
if (count($calls) > 0) {
365+
$serviceXML->appendChild($callsXML = $dom->createElement('calls'));
366+
foreach ($calls as $callData) {
367+
$callsXML->appendChild($callXML = $dom->createElement('call'));
368+
$callXML->setAttribute('method', $callData[0]);
369+
}
370+
}
371+
363372
if (!$omitTags) {
364373
$tags = $definition->getTags();
365374

Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static function getContainerDefinitions()
115115
->addTag('tag1', array('attr1' => 'val1', 'attr2' => 'val2'))
116116
->addTag('tag1', array('attr3' => 'val3'))
117117
->addTag('tag2')
118+
->addMethodCall('setMailer', array(new Reference('mailer')))
118119
->setFactory(array(new Reference('factory.service'), 'get')),
119120
);
120121
}

Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
]
4848
}
4949
],
50+
"calls": [
51+
"setMailer"
52+
],
5053
"autowire": false,
5154
"autowiring_types": []
5255
}

Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ definition_2
3030
- File: `/path/to/file`
3131
- Factory Service: `factory.service`
3232
- Factory Method: `get`
33+
- Call: `setMailer`
3334
- Tag: `tag1`
3435
- Attr1: val1
3536
- Attr2: val2

Tests/Fixtures/Descriptor/builder_1_services.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
</definition>
88
<definition id="definition_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" file="/path/to/file">
99
<factory service="factory.service" method="get"/>
10+
<calls>
11+
<call method="setMailer"/>
12+
</calls>
1013
<tags>
1114
<tag name="tag1">
1215
<parameter name="attr1">val1</parameter>

Tests/Fixtures/Descriptor/builder_1_tag1.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
]
3232
}
3333
],
34+
"calls": [
35+
"setMailer"
36+
],
3437
"autowire": false,
3538
"autowiring_types": []
3639
}

Tests/Fixtures/Descriptor/builder_1_tag1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ definition_2
1717
- File: `/path/to/file`
1818
- Factory Service: `factory.service`
1919
- Factory Method: `get`
20+
- Call: `setMailer`
2021
- Tag: `tag1`
2122
- Attr1: val1
2223
- Attr2: val2

0 commit comments

Comments
 (0)