Skip to content

Commit 536125a

Browse files
dunglasfabpot
authored andcommitted
[VarDumper] New env var to select the dump format
1 parent 26989d4 commit 536125a

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ public function __destruct()
204204
--$i;
205205
}
206206

207-
if (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true) && stripos($h[$i], 'html')) {
207+
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
208+
$html = 'html' === $_SERVER['VAR_DUMPER_FORMAT'];
209+
} else {
210+
$html = !\in_array(PHP_SAPI, array('cli', 'phpdbg'), true) && stripos($h[$i], 'html');
211+
}
212+
213+
if ($html) {
208214
$dumper = new HtmlDumper('php://output', $this->charset);
209215
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
210216
} else {

src/Symfony/Component/VarDumper/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* support selecting the format to use by setting the environment variable `VAR_DUMPER_FORMAT` to `html` or `cli`
8+
49
4.1.0
510
-----
611

src/Symfony/Component/VarDumper/VarDumper.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ class VarDumper
2727

2828
public static function dump($var)
2929
{
30-
if (null === self::$handler) {
31-
$cloner = new VarCloner();
32-
$dumper = \in_array(PHP_SAPI, array('cli', 'phpdbg'), true) ? new CliDumper() : new HtmlDumper();
33-
self::$handler = function ($var) use ($cloner, $dumper) {
34-
$dumper->dump($cloner->cloneVar($var));
35-
};
30+
if (null !== self::$handler) {
31+
return \call_user_func(self::$handler, $var);
3632
}
3733

38-
return call_user_func(self::$handler, $var);
34+
$cloner = new VarCloner();
35+
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
36+
$dumper = 'html' === $_SERVER['VAR_DUMPER_FORMAT'] ? new HtmlDumper() : new CliDumper();
37+
} else {
38+
$dumper = \in_array(PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper();
39+
}
40+
41+
self::$handler = function ($var) use ($cloner, $dumper) {
42+
$dumper->dump($cloner->cloneVar($var));
43+
};
3944
}
4045

4146
public static function setHandler(callable $callable = null)

0 commit comments

Comments
 (0)