diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 07f27563a2..658c04b546 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor; +use phpDocumentor\Reflection\DocBlockFactory; +use phpDocumentor\Reflection\DocBlockFactoryInterface; use Symfony\Component\Console\Descriptor\DescriptorInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\Alias; @@ -284,4 +286,29 @@ abstract class Descriptor implements DescriptorInterface return $serviceIds; } + + /** + * Get class description from doc block. + * + * @param string $class + * + * @return string + */ + protected function getClassDescription($class) + { + if (!interface_exists(DocBlockFactoryInterface::class)) { + return ''; + } + + try { + $reflectionProperty = new \ReflectionClass($class); + + return DocBlockFactory::createInstance() + ->create($reflectionProperty->getDocComment()) + ->getSummary(); + } catch (\ReflectionException $e) { + } + + return ''; + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 4bc8cafc41..f6badd0552 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -220,6 +220,10 @@ class JsonDescriptor extends Descriptor 'autoconfigure' => $definition->isAutoconfigured(), ); + if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) { + $data['description'] = $classDescription; + } + if ($showArguments) { $data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index d14af62767..85802d6975 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -181,7 +181,13 @@ class MarkdownDescriptor extends Descriptor */ protected function describeContainerDefinition(Definition $definition, array $options = array()) { - $output = '- Class: `'.$definition->getClass().'`' + $output = ''; + + if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) { + $output .= '- Description: `'.$classDescription.'`'."\n"; + } + + $output .= '- Class: `'.$definition->getClass().'`' ."\n".'- Public: '.($definition->isPublic() && !$definition->isPrivate() ? 'yes' : 'no') ."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no') ."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no') diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index b2dcc5f238..f1f064c4f5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -260,6 +260,10 @@ class TextDescriptor extends Descriptor $options['output']->title(sprintf('Information for Service "%s"', $options['id'])); } + if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) { + $options['output']->text($classDescription."\n"); + } + $tableHeaders = array('Option', 'Value'); $tableRows[] = array('Service ID', isset($options['id']) ? $options['id'] : '-'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 385444d228..bac8469fc9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -304,6 +304,11 @@ class XmlDescriptor extends Descriptor $serviceXML->setAttribute('id', $id); } + if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) { + $serviceXML->appendChild($descriptionXML = $dom->createElement('description')); + $descriptionXML->appendChild($dom->createCDATASection($classDescription)); + } + $serviceXML->setAttribute('class', $definition->getClass()); if ($factory = $definition->getFactory()) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json index bcafe91b64..959b24b3ff 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json @@ -76,6 +76,7 @@ "abstract": false, "autowire": false, "autoconfigure": false, + "description": "ContainerInterface is the interface implemented by service container classes.", "arguments": [], "file": null, "tags": [] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md index 2ace4d31cb..efdc188d43 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md @@ -20,6 +20,7 @@ Definitions ### service_container +- Description: `ContainerInterface is the interface implemented by service container classes.` - Class: `Symfony\Component\DependencyInjection\ContainerInterface` - Public: yes - Synthetic: yes diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml index 6efe597d8f..0a6cfb44a2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml @@ -23,5 +23,7 @@ - + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json index bb1ef32595..d96cf59951 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json @@ -23,6 +23,7 @@ "abstract": false, "autowire": false, "autoconfigure": false, + "description": "ContainerInterface is the interface implemented by service container classes.", "file": null, "tags": [] } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md index fedb514965..cf8aec87e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md @@ -19,6 +19,7 @@ Definitions ### service_container +- Description: `ContainerInterface is the interface implemented by service container classes.` - Class: `Symfony\Component\DependencyInjection\ContainerInterface` - Public: yes - Synthetic: yes diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml index 66aba252af..b6f6302713 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml @@ -4,5 +4,7 @@ - + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 4b665380c2..a3d2f6ab36 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -78,6 +78,7 @@ }, "suggest": { "ext-apcu": "For best performance of the system caches", + "phpdocumentor/reflection-docblock": "For display additional information in debug:container", "symfony/console": "For using the console commands", "symfony/form": "For using forms", "symfony/serializer": "For using the serializer service",