Skip to content

Commit

Permalink
[VarDumper] New env var to select the dump format
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas authored and fabpot committed Sep 4, 2018
1 parent 18423a6 commit 89d3d3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.2.0
-----

* support selecting the format to use by setting the environment variable `VAR_DUMPER_FORMAT` to `html` or `cli`

4.1.0
-----

Expand Down
19 changes: 12 additions & 7 deletions VarDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ class VarDumper

public static function dump($var)
{
if (null === self::$handler) {
$cloner = new VarCloner();
$dumper = \in_array(PHP_SAPI, array('cli', 'phpdbg'), true) ? new CliDumper() : new HtmlDumper();
self::$handler = function ($var) use ($cloner, $dumper) {
$dumper->dump($cloner->cloneVar($var));
};
if (null !== self::$handler) {
return \call_user_func(self::$handler, $var);
}

return call_user_func(self::$handler, $var);
$cloner = new VarCloner();
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
$dumper = 'html' === $_SERVER['VAR_DUMPER_FORMAT'] ? new HtmlDumper() : new CliDumper();
} else {
$dumper = \in_array(PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper();
}

self::$handler = function ($var) use ($cloner, $dumper) {
$dumper->dump($cloner->cloneVar($var));
};
}

public static function setHandler(callable $callable = null)
Expand Down

0 comments on commit 89d3d3c

Please sign in to comment.