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

Skip to content

Commit 0ab9f2c

Browse files
committed
[FrameworkBundle] add class description to debug:container command
1 parent dd2f830 commit 0ab9f2c

11 files changed

+57
-3
lines changed

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

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

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

14+
use phpDocumentor\Reflection\DocBlockFactory;
1415
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1617
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -220,6 +221,14 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
220221
'autoconfigure' => $definition->isAutoconfigured(),
221222
);
222223

224+
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
225+
try {
226+
$reflectionProperty = new \ReflectionClass($definition->getClass());
227+
$data['description'] = DocBlockFactory::createInstance()->create($reflectionProperty->getDocComment())->getSummary();
228+
} catch (\ReflectionException $e) {
229+
}
230+
}
231+
223232
if ($showArguments) {
224233
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
225234
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
use phpDocumentor\Reflection\DocBlockFactory;
1415
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
@@ -181,7 +182,18 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
181182
*/
182183
protected function describeContainerDefinition(Definition $definition, array $options = array())
183184
{
184-
$output = '- Class: `'.$definition->getClass().'`'
185+
$output = '';
186+
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
187+
try {
188+
$reflectionProperty = new \ReflectionClass($definition->getClass());
189+
$classDescription = DocBlockFactory::createInstance()->create($reflectionProperty->getDocComment())->getSummary();
190+
191+
$output = '- Description: `'.$classDescription.'`'."\n";
192+
} catch (\ReflectionException $e) {
193+
}
194+
}
195+
196+
$output .= '- Class: `'.$definition->getClass().'`'
185197
."\n".'- Public: '.($definition->isPublic() && !$definition->isPrivate() ? 'yes' : 'no')
186198
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
187199
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')

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

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

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

14+
use phpDocumentor\Reflection\DocBlockFactory;
1415
use Symfony\Component\Console\Formatter\OutputFormatter;
1516
use Symfony\Component\Console\Helper\Table;
1617
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -260,6 +261,16 @@ protected function describeContainerDefinition(Definition $definition, array $op
260261
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $options['id']));
261262
}
262263

264+
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
265+
try {
266+
$reflectionProperty = new \ReflectionClass($definition->getClass());
267+
$classDescription = DocBlockFactory::createInstance()->create($reflectionProperty->getDocComment())->getSummary();
268+
269+
$options['output']->text($classDescription."\n");
270+
} catch (\ReflectionException $e) {
271+
}
272+
}
273+
263274
$tableHeaders = array('Option', 'Value');
264275

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

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

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

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

14+
use phpDocumentor\Reflection\DocBlockFactory;
1415
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1617
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -304,6 +305,18 @@ private function getContainerDefinitionDocument(Definition $definition, string $
304305
$serviceXML->setAttribute('id', $id);
305306
}
306307

308+
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
309+
try {
310+
$reflectionProperty = new \ReflectionClass($definition->getClass());
311+
$classDescription = DocBlockFactory::createInstance()->create($reflectionProperty->getDocComment())->getSummary();
312+
313+
$serviceXML->appendChild($descriptionXML = $dom->createElement('description'));
314+
315+
$descriptionXML->appendChild($dom->createCDATASection($classDescription));
316+
} catch (\ReflectionException $e) {
317+
}
318+
}
319+
307320
$serviceXML->setAttribute('class', $definition->getClass());
308321

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