Skip to content

Commit 0933b8d

Browse files
committed
Add class link
1 parent 245451a commit 0933b8d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@
196196
</service>
197197

198198
<service id="console.command.error_renderer_debug" class="Symfony\Component\ErrorRenderer\Command\DebugCommand">
199-
<argument type="collection" />
199+
<argument type="collection" /> <!-- All error renderers are injected here by ErrorRendererPass -->
200+
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
200201
<tag name="console.command" command="debug:error-renderer" />
201202
</service>
202203
</services>

src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Console\Style\SymfonyStyle;
2020
use Symfony\Component\ErrorRenderer\ErrorRenderer\ErrorRendererInterface;
2121
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
22+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
2223

2324
/**
2425
* A console command for retrieving information about error renderers.
@@ -32,13 +33,15 @@ class DebugCommand extends Command
3233
protected static $defaultName = 'debug:error-renderer';
3334

3435
private $renderers;
36+
private $fileLinkFormatter;
3537

3638
/**
3739
* @param ErrorRendererInterface[] $renderers
3840
*/
39-
public function __construct(array $renderers)
41+
public function __construct(array $renderers, FileLinkFormatter $fileLinkFormatter = null)
4042
{
4143
$this->renderers = $renderers;
44+
$this->fileLinkFormatter = $fileLinkFormatter;
4245

4346
parent::__construct();
4447
}
@@ -84,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8487
} else {
8588
$tableRows = [];
8689
foreach ($renderers as $format => $renderer) {
87-
$tableRows[] = [sprintf('<fg=cyan>%s</fg=cyan>', $format), \get_class($renderer)];
90+
$tableRows[] = [sprintf('<fg=cyan>%s</fg=cyan>', $format), $this->formatClassLink(\get_class($renderer))];
8891
}
8992

9093
$io->title('Error Renderers');
@@ -93,4 +96,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
9396
$io->table(['Format', 'Class'], $tableRows);
9497
}
9598
}
99+
100+
private function formatClassLink(string $class): string
101+
{
102+
if ('' === $fileLink = $this->getFileLink($class)) {
103+
return $class;
104+
}
105+
106+
return sprintf('<href=%s>%s</>', $fileLink, $class);
107+
}
108+
109+
private function getFileLink(string $class): string
110+
{
111+
if (null === $this->fileLinkFormatter) {
112+
return '';
113+
}
114+
115+
try {
116+
$r = new \ReflectionClass($class);
117+
} catch (\ReflectionException $e) {
118+
return '';
119+
}
120+
121+
return $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
122+
}
96123
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy