diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml index f753b21419..050144e5a8 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 3a86e26691..5aed307f44 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\Console\Helper\DescriptorHelper; 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 @@ class DebugCommand extends Command $this->types = $types; $this->extensions = $extensions; $this->guessers = $guessers; + $this->fileLinkFormatter = $fileLinkFormatter; } /** @@ -145,7 +148,7 @@ EOF } } - $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 da0fc652f6..176be3cd7b 100644 --- a/src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Console\Descriptor; 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 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ 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 @@ class TextDescriptor extends Descriptor 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 @@ class TextDescriptor extends Descriptor 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 @@ class TextDescriptor extends Descriptor 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 e850324c01..355fb95989 100644 --- a/src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Console\Helper; 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 @@ use Symfony\Component\Form\Console\Descriptor\TextDescriptor; */ 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()) ; }