Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dcba01d

Browse filesBrowse files
committed
Add file links for described classes
1 parent 9bcea2e commit dcba01d
Copy full SHA for dcba01d

File tree

4 files changed

+53
-10
lines changed
Filter options

4 files changed

+53
-10
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<argument type="collection" /> <!-- All services form types are stored here by FormPass -->
161161
<argument type="collection" /> <!-- All type extensions are stored here by FormPass -->
162162
<argument type="collection" /> <!-- All type guessers are stored here by FormPass -->
163+
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
163164
<tag name="console.command" command="debug:form" />
164165
</service>
165166
</services>

‎src/Symfony/Component/Form/Command/DebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Command/DebugCommand.php
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Form\Extension\Core\CoreExtension;
2323
use Symfony\Component\Form\FormRegistryInterface;
2424
use Symfony\Component\Form\FormTypeInterface;
25+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
2526

2627
/**
2728
* A console command for retrieving information about form types.
@@ -37,8 +38,9 @@ class DebugCommand extends Command
3738
private $types;
3839
private $extensions;
3940
private $guessers;
41+
private $fileLinkFormatter;
4042

41-
public function __construct(FormRegistryInterface $formRegistry, array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [], array $extensions = [], array $guessers = [])
43+
public function __construct(FormRegistryInterface $formRegistry, array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [], array $extensions = [], array $guessers = [], FileLinkFormatter $fileLinkFormatter = null)
4244
{
4345
parent::__construct();
4446

@@ -47,6 +49,7 @@ public function __construct(FormRegistryInterface $formRegistry, array $namespac
4749
$this->types = $types;
4850
$this->extensions = $extensions;
4951
$this->guessers = $guessers;
52+
$this->fileLinkFormatter = $fileLinkFormatter;
5053
}
5154

5255
/**
@@ -145,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
145148
}
146149
}
147150

148-
$helper = new DescriptorHelper();
151+
$helper = new DescriptorHelper($this->fileLinkFormatter);
149152
$options['format'] = $input->getOption('format');
150153
$options['show_deprecated'] = $input->getOption('show-deprecated');
151154
$helper->describe($io, $object, $options);

‎src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php
+44-6Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Helper\Dumper;
1515
use Symfony\Component\Console\Helper\TableSeparator;
1616
use Symfony\Component\Form\ResolvedFormTypeInterface;
17+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1718
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

1920
/**
@@ -23,30 +24,39 @@
2324
*/
2425
class TextDescriptor extends Descriptor
2526
{
27+
private $fileLinkFormatter;
28+
29+
public function __construct(FileLinkFormatter $fileLinkFormatter = null)
30+
{
31+
$this->fileLinkFormatter = $fileLinkFormatter;
32+
}
33+
2634
protected function describeDefaults(array $options)
2735
{
2836
if ($options['core_types']) {
2937
$this->output->section('Built-in form types (Symfony\Component\Form\Extension\Core\Type)');
30-
$shortClassNames = array_map(function ($fqcn) { return \array_slice(explode('\\', $fqcn), -1)[0]; }, $options['core_types']);
38+
$shortClassNames = array_map(function ($fqcn) {
39+
return $this->formatClassLink($fqcn, \array_slice(explode('\\', $fqcn), -1)[0]);
40+
}, $options['core_types']);
3141
for ($i = 0, $loopsMax = \count($shortClassNames); $i * 5 < $loopsMax; ++$i) {
3242
$this->output->writeln(' '.implode(', ', \array_slice($shortClassNames, $i * 5, 5)));
3343
}
3444
}
3545

3646
if ($options['service_types']) {
3747
$this->output->section('Service form types');
38-
$this->output->listing($options['service_types']);
48+
$this->output->listing(array_map([$this, 'formatClassLink'], $options['service_types']));
3949
}
4050

4151
if (!$options['show_deprecated']) {
4252
if ($options['extensions']) {
4353
$this->output->section('Type extensions');
44-
$this->output->listing($options['extensions']);
54+
$this->output->listing(array_map([$this, 'formatClassLink'], $options['extensions']));
4555
}
4656

4757
if ($options['guessers']) {
4858
$this->output->section('Type guessers');
49-
$this->output->listing($options['guessers']);
59+
$this->output->listing(array_map([$this, 'formatClassLink'], $options['guessers']));
5060
}
5161
}
5262
}
@@ -82,12 +92,12 @@ protected function describeResolvedFormType(ResolvedFormTypeInterface $resolvedF
8292

8393
if ($this->parents) {
8494
$this->output->section('Parent types');
85-
$this->output->listing($this->parents);
95+
$this->output->listing(array_map([$this, 'formatClassLink'], $this->parents));
8696
}
8797

8898
if ($this->extensions) {
8999
$this->output->section('Type extensions');
90-
$this->output->listing($this->extensions);
100+
$this->output->listing(array_map([$this, 'formatClassLink'], $this->extensions));
91101
}
92102
}
93103

@@ -178,4 +188,32 @@ private function normalizeAndSortOptionsColumns(array $options)
178188

179189
return $options;
180190
}
191+
192+
private function formatClassLink(string $class, string $text = null): string
193+
{
194+
if (null === $text) {
195+
$text = $class;
196+
}
197+
198+
if ('' === $fileLink = $this->getFileLink($class)) {
199+
return $text;
200+
}
201+
202+
return sprintf('<href=%s>%s</>', $fileLink, $text);
203+
}
204+
205+
private function getFileLink(string $class): string
206+
{
207+
if (null === $this->fileLinkFormatter) {
208+
return '';
209+
}
210+
211+
try {
212+
$r = new \ReflectionClass($class);
213+
} catch (\ReflectionException $e) {
214+
return '';
215+
}
216+
217+
return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
218+
}
181219
}

‎src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Console/Helper/DescriptorHelper.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Helper\DescriptorHelper as BaseDescriptorHelper;
1515
use Symfony\Component\Form\Console\Descriptor\JsonDescriptor;
1616
use Symfony\Component\Form\Console\Descriptor\TextDescriptor;
17+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1718

1819
/**
1920
* @author Yonel Ceruto <yonelceruto@gmail.com>
@@ -22,10 +23,10 @@
2223
*/
2324
class DescriptorHelper extends BaseDescriptorHelper
2425
{
25-
public function __construct()
26+
public function __construct(FileLinkFormatter $fileLinkFormatter = null)
2627
{
2728
$this
28-
->register('txt', new TextDescriptor())
29+
->register('txt', new TextDescriptor($fileLinkFormatter))
2930
->register('json', new JsonDescriptor())
3031
;
3132
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.