8000 bug #53842 [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env… · priyadi/symfony@22efc29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22efc29

Browse files
bug symfony#53842 [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT When using `dump()` in a plain PHP script, `SYMFONY_IDE` is currently ignored. This fixes it when `FileLinkFormatter` is available. Commits ------- 266ab4e [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var
2 parents 8f98550 + 266ab4e commit 22efc29

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
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: 28 additions & 1 deletion
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;
@@ -479,7 +480,7 @@ public function testCollapse()
479480
],
480481
[
481482
'bar' => 123,
482-
]
483+
],
483484
]);
484485

485486
$dumper = new CliDumper();
@@ -499,4 +500,30 @@ 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< 9695 code class="diff-text syntax-highlighted-line addition">+
$ide = $_ENV['SYMFONY_IDE'] ?? null;
513+
$_ENV['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:%sCliDumperTest%s', $dump);
521+
} finally {
522+
if (null === $ide) {
523+
unset($_ENV['SYMFONY_IDE']);
524+
} else {
525+
$_ENV['SYMFONY_IDE'] = $ide;
526+
}
527+
}
528+
}
502529
}

0 commit comments

Comments
 (0)
0