Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fc6155

Browse files
committed
[FrameworkBundle] add class description to debug:container command
1 parent a1aee05 commit 5fc6155

12 files changed

+58
-3
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

14+
use phpDocumentor\Reflection\DocBlockFactory;
15+
use phpDocumentor\Reflection\DocBlockFactoryInterface;
1416
use Symfony\Component\Console\Descriptor\DescriptorInterface;
1517
use Symfony\Component\Console\Output\OutputInterface;
1618
use Symfony\Component\DependencyInjection\Alias;
@@ -284,4 +286,29 @@ protected function sortServiceIds(array $serviceIds)
284286

285287
return $serviceIds;
286288
}
289+
290+
/**
291+
* Get class description from doc block.
292+
*
293+
* @param string $class
294+
*
295+
* @return string
296+
*/
297+
protected function getClassDescription($class)
298+
{
299+
if (!interface_exists(DocBlockFactoryInterface::class)) {
300+
return '';
301+
}
302+
303+
try {
304+
$reflectionProperty = new \ReflectionClass($class);
305+
306+
return DocBlockFactory::createInstance()
307+
->create($reflectionProperty->getDocComment())
308+
->getSummary();
309+
} catch (\ReflectionException $e) {
310+
}
311+
312+
return '';
313+
}
287314
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
220220
'autoconfigure' => $definition->isAutoconfigured(),
221221
);
222222

223+
if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) {
224+
$data['description'] = $classDescription;
225+
}
226+
223227
if ($showArguments) {
224228
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
225229
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,13 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
181181
*/
182182
protected function describeContainerDefinition(Definition $definition, array $options = array())
183183
{
184-
$output = '- Class: `'.$definition->getClass().'`'
184+
$output = '';
185+
186+
if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) {
187+
$output .= '- Description: `'.$classDescription.'`'."\n";
188+
}
189+
190+
$output .= '- Class: `'.$definition->getClass().'`'
185191
."\n".'- Public: '.($definition->isPublic() && !$definition->isPrivate() ? 'yes' : 'no')
186192
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
187193
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ protected function describeContainerDefinition(Definition $definition, array $op
260260
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $options['id']));
261261
}
262262

263+
if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) {
264+
$options['output']->text($classDescription."\n");
265+
}
266+
263267
$tableHeaders = array('Option', 'Value');
264268

265269
$tableRows[] = array('Service ID', isset($options['id']) ? $options['id'] : '-');

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ private function getContainerDefinitionDocument(Definition $definition, string $
304304
$serviceXML->setAttribute('id', $id);
305305
}
306306

307+
if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) {
308+
$serviceXML->appendChild($descriptionXML = $dom->createElement('description'));
309+
$descriptionXML->appendChild($dom->createCDATASection($classDescription));
310+
}
311+
307312
$serviceXML->setAttribute('class', $definition->getClass());
308313

309314
if ($factory = $definition->getFactory()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"abstract": false,
7777
"autowire": false,
7878
"autoconfigure": false,
79+
"description": "ContainerInterface is the interface implemented by service container classes.",
7980
"arguments": [],
8081
"file": null,
8182
"tags": []

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Definitions
2020

2121
### service_container
2222

23+
- Description: `ContainerInterface is the interface implemented by service container classes.`
2324
- Class: `Symfony\Component\DependencyInjection\ContainerInterface`
2425
- Public: yes
2526
- Synthetic: yes

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@
2323
<argument type="service" id=".definition_2"/>
2424
</argument>
2525
</definition>
26-
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file=""/>
26+
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">
27+
<description><![CDATA[ContainerInterface is the interface implemented by service container classes.]]></description>
28+
</definition>
2729
</container>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"abstract": false,
2424
"autowire": false,
2525
"autoconfigure": false,
26+
"description": "ContainerInterface is the interface implemented by service container classes.",
2627
"file": null,
2728
"tags": []
2829
}

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
@@ -19,6 +19,7 @@ Definitions
1919

2020
### service_container
2121

22+
- Description: `ContainerInterface is the interface implemented by service container classes.`
2223
- Class: `Symfony\Component\DependencyInjection\ContainerInterface`
2324
- Public: yes
2425
- Synthetic: yes

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" autoconfigured="false" file="">
55
<factory class="Full\Qualified\FactoryClass" method="get"/>
66
</definition>
7-
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file=""/>
7+
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">
8+
<description><![CDATA[ContainerInterface is the interface implemented by service container classes.]]></description>
9+
</definition>
810
</container>

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
},
7878
"suggest": {
7979
"ext-apcu": "For best performance of the system caches",
80+
"phpdocumentor/reflection-docblock": "For display additional information in debug:container",
8081
"symfony/console": "For using the console commands",
8182
"symfony/form": "For using forms",
8283
"symfony/serializer": "For using the serializer service",

0 commit comments

Comments
 (0)