8000 [FrameworkBundle] add class description to debug:container command by gimler · Pull Request #28117 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] add class description to debug:container command #28117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -284,4 +286,29 @@ protected function sortServiceIds(array $serviceIds)

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 '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
'autoconfigure' => $definition->isAutoconfigured(),
);

if ('' !== $classDescription = $this->getClassDescription($definition->getClass())) {
$data['description'] = $classDescription;
}

if ($showArguments) {
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
*/
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ protected function describeContainerDefinition(Definition $definition, array $op
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $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'] : '-');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ private function getContainerDefinitionDocument(Definition $definition, string $
$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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"abstract": false,
"autowire": false,
"autoconfigure": false,
"description": "ContainerInterface is the interface implemented by service container classes.",
"arguments": [],
"file": null,
"tags": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
<argument type="service" id=".definition_2"/>
</argument>
</definition>
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file=""/>
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">
<description><![CDATA[ContainerInterface is the interface implemented by service container classes.]]></description>
</definition>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"abstract": false,
"autowire": false,
"autoconfigure": false,
"description": "ContainerInterface is the interface implemented by service container classes.",
"file": null,
"tags": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" autoconfigured="false" file="">
<factory class="Full\Qualified\FactoryClass" method="get"/>
</definition>
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file=""/>
<definition id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">
<description><![CDATA[ContainerInterface is the interface implemented by service container classes.]]></description>
</definition>
</container>
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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",
Expand Down
0