8000 [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var · symfony/symfony@2248a8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2248a8c

Browse files
[VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var
1 parent 7cda7b4 commit 2248a8c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Symfony/Component/ErrorHandler/ErrorRenderer/FileLinkFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FileLinkFormatter
3030
private \Closure|string|null $urlFormat;
3131

3232
/**
33-
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
33+
* @param string|\Closure $urlFormat The URL format, or a closure that returns it on-demand
3434
*/
3535
public function __construct(string|array|null $fileLinkFormat = null, ?RequestStack $requestStack = null, ?string $baseDir = null, string|\Closure|null $urlFormat = null)
3636
{

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\VarDumper\Dumper;
1313

14+
use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
1415
use Symfony\Component\VarDumper\Cloner\Cursor;
1516
use Symfony\Component\VarDumper\Cloner\Stub;
1617

@@ -82,7 +83,7 @@ public function __construct($output = null, ?string $charset = null, int $flags
8283
]);
8384
}
8485

85-
$this->displayOptions['fileLinkFormat'] = \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l';
86+
$this->displayOptions['fileLinkFormat'] = class_exists(FileLinkFormatter::class) ? new FileLinkFormatter() : (\ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l');
8687
}
8788

8889
/**

src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\VarDumper\Tests\Dumper;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarDumper\Caster\ClassStub;
1516
use Symfony\Component\VarDumper\Caster\CutStub;
1617
use Symfony\Component\VarDumper\Cloner\Data;
1718
use Symfony\Component\VarDumper\Cloner\Stub;
@@ -499,4 +500,26 @@ public function testCollapse()
499500
$dump
500501
);
501502
}
503+
504+
public function testFileLinkFormat()
505+
{
506+
$data = new Data([
507+
[
508+
new ClassStub(self::class),
509+
],
510+
]);
511+
512+
$ide = getenv('SYMFONY_IDE');
513+
putenv('SYMFONY_IDE=vscode');
514+
515+
try {
516+
$dumper = new CliDumper();
517+
$dumper->setColors(true);
518+
$dump = $dumper->dump($data, true);
519+
520+
$this->assertStringMatchesFormat('%svscode://file/%s/CliDumperTest.php:%sCliDumperTest%s', $dump);
521+
} finally {
522+
putenv('SYMFONY_IDE'.($ide ? '='.$ide : ''));
523+
}
524+
}
502525
}

0 commit comments

Comments
 (0)
0