function DebugDump::cliHandler
A CLI handler for \Symfony\Component\VarDumper\VarDumper.
Parameters
mixed $var: The variable to be dumped.
File
-
core/
tests/ Drupal/ TestTools/ Extension/ Dump/ DebugDump.php, line 84
Class
- DebugDump
- Drupal's extension for printing dump() output results.
Namespace
Drupal\TestTools\Extension\DumpCode
public static function cliHandler(mixed $var) : void {
if (!self::isEnabled()) {
return;
}
$config = (array) json_decode(getenv('DRUPAL_PHPUNIT_DUMPER_CONFIG'));
$caller = self::getCaller();
$cloner = new VarCloner();
$dumper = new CliDumper();
$dumper->setColors($config['colors']);
$dump = [];
$dumper->dump($cloner->cloneVar($var), function ($line, $depth, $indent_pad) use (&$dump) {
// A negative depth means "end of dump".
if ($depth >= 0) {
// Adds a two spaces indentation to the line.
$dump[] = str_repeat($indent_pad, $depth) . $line;
}
});
file_put_contents($config['stagingFilePath'], self::encodeDump($caller['test']->id(), $caller['file'], $caller['line'], $dump) . "\n", FILE_APPEND);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.