8000 bug #37841 [VarDumper] Backport handler lock when using VAR_DUMPER_FO… · symfony/symfony@7f2726a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f2726a

Browse files
committed
bug #37841 [VarDumper] Backport handler lock when using VAR_DUMPER_FORMAT (ogizanagi)
This PR was merged into the 4.4 branch. Discussion ---------- [VarDumper] Backport handler lock when using VAR_DUMPER_FORMAT | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | N/A Backport of the "lock" behavior from #35967, preventing unexpected handler change when using the `VAR_DUMPER_FORMAT` env var. --- As a concrete example of this not working as expected: Start a PHPUnit test suite with this env var to the desired format. If a web test case is making a request (with debug enabled), the `DebugBundle` replaces the handler set initially by the `VAR_DUMPER_FORMAT`, will collect dumps into the profiler, but won't output these. As well, for dumps made in between the the kernel is boot (`DebugBundle::build()` is called) and a request, the dumps are properly sent to the output with expected format, but looses colors. IMHO, the use-cases of `VAR_DUMPER_FORMAT` justifies locking the handler for the whole process. Commits ------- 19b341e [VarDumper] Backport handler lock when using VAR_DUMPER_FORMAT
2 parents 0bb2a1a + 19b341e commit 7f2726a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,7 @@ public function __destruct()
235235
--$i;
236236
}
237237

238-
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
239-
$html = 'html' === $_SERVER['VAR_DUMPER_FORMAT'];
240-
} else {
241-
$html = !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html');
242-
}
243-
244-
if ($html) {
238+
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) {
245239
$dumper = new HtmlDumper('php://output', $this->charset);
246240
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
247241
} else {

src/Symfony/Component/VarDumper/VarDumper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public static function dump($var)
5353
public static function setHandler(callable $callable = null)
5454
{
5555
$prevHandler = self::$handler;
56+
57+
// Prevent replacing the handler with expected format as soon as the env var was set:
58+
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
59+
return $prevHandler;
60+
}
61+
5662
self::$handler = $callable;
5763

5864
return $prevHandler;

0 commit comments

Comments
 (0)
0