diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
index f753b214192da..050144e5a8b24 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
@@ -160,6 +160,7 @@
+
diff --git a/src/Symfony/Component/Form/Command/DebugCommand.php b/src/Symfony/Component/Form/Command/DebugCommand.php
index 3a86e2669192c..5aed307f44cdd 100644
--- a/src/Symfony/Component/Form/Command/DebugCommand.php
+++ b/src/Symfony/Component/Form/Command/DebugCommand.php
@@ -22,6 +22,7 @@
use Symfony\Component\Form\Extension\Core\CoreExtension;
use Symfony\Component\Form\FormRegistryInterface;
use Symfony\Component\Form\FormTypeInterface;
+use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
/**
* A console command for retrieving information about form types.
@@ -37,8 +38,9 @@ class DebugCommand extends Command
private $types;
private $extensions;
private $guessers;
+ private $fileLinkFormatter;
- public function __construct(FormRegistryInterface $formRegistry, array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [], array $extensions = [], array $guessers = [])
+ public function __construct(FormRegistryInterface $formRegistry, array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [], array $extensions = [], array $guessers = [], FileLinkFormatter $fileLinkFormatter = null)
{
parent::__construct();
@@ -47,6 +49,7 @@ public function __construct(FormRegistryInterface $formRegistry, array $namespac
$this->types = $types;
$this->extensions = $extensions;
$this->guessers = $guessers;
+ $this->fileLinkFormatter = $fileLinkFormatter;
}
/**
@@ -145,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
- $helper = new DescriptorHelper();
+ $helper = new DescriptorHelper($this->fileLinkFormatter);
$options['format'] = $input->getOption('format');
$options['show_deprecated'] = $input->getOption('show-deprecated');
$helper->describe($io, $object, $options);
diff --git a/src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php
index da0fc652f6d21..176be3cd7b8df 100644
--- a/src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php
+++ b/src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php
@@ -14,6 +14,7 @@
use Symfony\Component\Console\Helper\Dumper;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Form\ResolvedFormTypeInterface;
+use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
@@ -23,11 +24,20 @@
*/
class TextDescriptor extends Descriptor
{
+ private $fileLinkFormatter;
+
+ public function __construct(FileLinkFormatter $fileLinkFormatter = null)
+ {
+ $this->fileLinkFormatter = $fileLinkFormatter;
+ }
+
protected function describeDefaults(array $options)
{
if ($options['core_types']) {
$this->output->section('Built-in form types (Symfony\Component\Form\Extension\Core\Type)');
- $shortClassNames = array_map(function ($fqcn) { return \array_slice(explode('\\', $fqcn), -1)[0]; }, $options['core_types']);
+ $shortClassNames = array_map(function ($fqcn) {
+ return $this->formatClassLink($fqcn, \array_slice(explode('\\', $fqcn), -1)[0]);
+ }, $options['core_types']);
for ($i = 0, $loopsMax = \count($shortClassNames); $i * 5 < $loopsMax; ++$i) {
$this->output->writeln(' '.implode(', ', \array_slice($shortClassNames, $i * 5, 5)));
}
@@ -35,18 +45,18 @@ protected function describeDefaults(array $options)
if ($options['service_types']) {
$this->output->section('Service form types');
- $this->output->listing($options['service_types']);
+ $this->output->listing(array_map([$this, 'formatClassLink'], $options['service_types']));
}
if (!$options['show_deprecated']) {
if ($options['extensions']) {
$this->output->section('Type extensions');
- $this->output->listing($options['extensions']);
+ $this->output->listing(array_map([$this, 'formatClassLink'], $options['extensions']));
}
if ($options['guessers']) {
$this->output->section('Type guessers');
- $this->output->listing($options['guessers']);
+ $this->output->listing(array_map([$this, 'formatClassLink'], $options['guessers']));
}
}
}
@@ -82,12 +92,12 @@ protected function describeResolvedFormType(ResolvedFormTypeInterface $resolvedF
if ($this->parents) {
$this->output->section('Parent types');
- $this->output->listing($this->parents);
+ $this->output->listing(array_map([$this, 'formatClassLink'], $this->parents));
}
if ($this->extensions) {
$this->output->section('Type extensions');
- $this->output->listing($this->extensions);
+ $this->output->listing(array_map([$this, 'formatClassLink'], $this->extensions));
}
}
@@ -178,4 +188,32 @@ private function normalizeAndSortOptionsColumns(array $options)
return $options;
}
+
+ private function formatClassLink(string $class, string $text = null): string
+ {
+ if (null === $text) {
+ $text = $class;
+ }
+
+ if ('' === $fileLink = $this->getFileLink($class)) {
+ return $text;
+ }
+
+ return sprintf('%s>', $fileLink, $text);
+ }
+
+ private function getFileLink(string $class): string
+ {
+ if (null === $this->fileLinkFormatter) {
+ return '';
+ }
+
+ try {
+ $r = new \ReflectionClass($class);
+ } catch (\ReflectionException $e) {
+ return '';
+ }
+
+ return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
+ }
}
diff --git a/src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php
index e850324c01712..355fb95989a36 100644
--- a/src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php
+++ b/src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php
@@ -14,6 +14,7 @@
use Symfony\Component\Console\Helper\DescriptorHelper as BaseDescriptorHelper;
use Symfony\Component\Form\Console\Descriptor\JsonDescriptor;
use Symfony\Component\Form\Console\Descriptor\TextDescriptor;
+use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
/**
* @author Yonel Ceruto
@@ -22,10 +23,10 @@
*/
class DescriptorHelper extends BaseDescriptorHelper
{
- public function __construct()
+ public function __construct(FileLinkFormatter $fileLinkFormatter = null)
{
$this
- ->register('txt', new TextDescriptor())
+ ->register('txt', new TextDescriptor($fileLinkFormatter))
->register('json', new JsonDescriptor())
;
}