2014-08-27 16:29:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\VarDumper;
|
|
|
|
|
2019-02-19 14:09:31 +00:00
|
|
|
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
|
2014-10-06 07:45:07 +01:00
|
|
|
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
2014-08-27 16:29:38 +01:00
|
|
|
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
|
|
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
|
|
|
|
2014-11-04 15:31:37 +00:00
|
|
|
// Load the global dump() function
|
|
|
|
require_once __DIR__.'/Resources/functions/dump.php';
|
|
|
|
|
2014-08-27 16:29:38 +01:00
|
|
|
/**
|
|
|
|
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
|
*/
|
|
|
|
class VarDumper
|
|
|
|
{
|
|
|
|
private static $handler;
|
|
|
|
|
|
|
|
public static function dump($var)
|
|
|
|
{
|
2018-09-06 18:01:56 +01:00
|
|
|
if (null === self::$handler) {
|
|
|
|
$cloner = new VarCloner();
|
2019-02-19 14:09:31 +00:00
|
|
|
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
|
2018-09-06 18:01:56 +01:00
|
|
|
|
|
|
|
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
|
|
|
|
$dumper = 'html' === $_SERVER['VAR_DUMPER_FORMAT'] ? new HtmlDumper() : new CliDumper();
|
|
|
|
} else {
|
2019-01-16 20:35:37 +00:00
|
|
|
$dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper() : new HtmlDumper();
|
2018-09-06 18:01:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self::$handler = function ($var) use ($cloner, $dumper) {
|
|
|
|
$dumper->dump($cloner->cloneVar($var));
|
|
|
|
};
|
2014-08-27 16:29:38 +01:00
|
|
|
}
|
|
|
|
|
2018-11-25 01:27:51 +00:00
|
|
|
return (self::$handler)($var);
|
2014-08-27 16:29:38 +01:00
|
|
|
}
|
|
|
|
|
2015-10-05 17:52:37 +01:00
|
|
|
public static function setHandler(callable $callable = null)
|
2014-08-27 16:29:38 +01:00
|
|
|
{
|
|
|
|
$prevHandler = self::$handler;
|
|
|
|
self::$handler = $callable;
|
|
|
|
|
|
|
|
return $prevHandler;
|
|
|
|
}
|
|
|
|
}
|