Skip to content

Commit e54e219

Browse files
committed
[VarDumper] Use hyperlinks in CliDescriptor
1 parent f2590d1 commit e54e219

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\VarDumper\Command\Descriptor;
1313

14+
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1415
use Symfony\Component\Console\Input\ArrayInput;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -28,10 +29,12 @@ class CliDescriptor implements DumpDescriptorInterface
2829
{
2930
private $dumper;
3031
private $lastIdentifier;
32+
private $supportsHref;
3133

3234
public function __construct(CliDumper $dumper)
3335
{
3436
$this->dumper = $dumper;
37+
$this->supportsHref = method_exists(OutputFormatterStyle::class, 'setHref');
3538
}
3639

3740
public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
@@ -62,15 +65,19 @@ public function describe(OutputInterface $output, Data $data, array $context, in
6265

6366
if (isset($context['source'])) {
6467
$source = $context['source'];
65-
$rows[] = array('source', sprintf('%s on line %d', $source['name'], $source['line']));
68+
$sourceInfo = sprintf('%s on line %d', $source['name'], $source['line']);
69+
$fileLink = $source['file_link'] ?? null;
70+
if ($this->supportsHref && $fileLink) {
71+
$sourceInfo = sprintf('<href=%s>%s</>', $fileLink, $sourceInfo);
72+
}
73+
$rows[] = array('source', $sourceInfo);
6674
$file = $source['file_relative'] ?? $source['file'];
6775
$rows[] = array('file', $file);
68-
$fileLink = $source['file_link'] ?? null;
6976
}
7077

7178
$io->table(array(), $rows);
7279

73-
if (isset($fileLink)) {
80+
if (!$this->supportsHref && isset($fileLink)) {
7481
$io->writeln(array('<info>Open source in your IDE/browser:</info>', $fileLink));
7582
$io->newLine();
7683
}

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