[DebugBundle] Added 'theme' option to change the color of dump() when rendered inside templates

This commit is contained in:
Daniel Gonzalez 2018-12-08 14:17:19 +00:00 committed by Fabien Potencier
parent 10b3d0055a
commit 91e8057d9a
2 changed files with 22 additions and 2 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\DebugBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
/**
* DebugExtension configuration structure.
@ -28,8 +29,8 @@ class Configuration implements ConfigurationInterface
{
$treeBuilder = new TreeBuilder('debug');
$treeBuilder->getRootNode()
->children()
$rootNode = $treeBuilder->getRootNode();
$rootNode->children()
->integerNode('max_items')
->info('Max number of displayed items past the first level, -1 means no limit')
->min(-1)
@ -53,6 +54,19 @@ class Configuration implements ConfigurationInterface
->end()
;
if (method_exists(HtmlDumper::class, 'setTheme')) {
$rootNode
->children()
->enumNode('theme')
->info('Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light"')
->example('dark')
->values(array('dark', 'light'))
->defaultValue('dark')
->end()
->end()
;
}
return $treeBuilder;
}
}

View File

@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
/**
* DebugExtension.
@ -42,6 +43,11 @@ class DebugExtension extends Extension
->addMethodCall('setMinDepth', array($config['min_depth']))
->addMethodCall('setMaxString', array($config['max_string_length']));
if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
$container->getDefinition('var_dumper.html_dumper')
->addMethodCall('setTheme', array($config['theme']));
}
if (null === $config['dump_destination']) {
$container->getDefinition('var_dumper.command.server_dump')
->setClass(ServerDumpPlaceholderCommand::class)