Last active
September 7, 2020 13:28
-
-
Save batkor/d79090cc05a20d909ab913f5b7c82057 to your computer and use it in GitHub Desktop.
VarDamper handler for > Drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Drupal\filter\Render\FilteredMarkup; | |
use Symfony\Component\VarDumper\Cloner\VarCloner; | |
use Symfony\Component\VarDumper\Dumper\CliDumper; | |
use Symfony\Component\VarDumper\Dumper\HtmlDumper; | |
use Symfony\Component\VarDumper\VarDumper; | |
// Set handler for VarDumper. | |
VarDumper::setHandler(function ($var) { | |
$cloner = new VarCloner(); | |
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper(); | |
$output = fopen('php://memory', 'r+b'); | |
$dumper->dump($cloner->cloneVar($var), $output); | |
$output = stream_get_contents($output, -1, 0); | |
$output = (string) $output; | |
$output = FilteredMarkup::create($output); | |
\Drupal::messenger()->addMessage($output); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment