Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c705b82

Browse files
committed
[VarDumper] Allow to use a light theme out of the box
1 parent cbe2895 commit c705b82

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,49 @@ class HtmlDumper extends CliDumper
2323
{
2424
public static $defaultOutput = 'php://output';
2525

26+
protected static $themes = array(
27+
'dark' => array(
28+
'default' => 'background-color:#18171B; color:#FF8400; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all',
29+
'num' => 'font-weight:bold; color:#1299DA',
30+
'const' => 'font-weight:bold',
31+
'str' => 'font-weight:bold; color:#56DB3A',
32+
'note' => 'color:#1299DA',
33+
'ref' => 'color:#A0A0A0',
34+
'public' => 'color:#FFFFFF',
35+
'protected' => 'color:#FFFFFF',
36+
'private' => 'color:#FFFFFF',
37+
'meta' => 'color:#B729D9',
38+
'key' => 'color:#56DB3A',
39+
'index' => 'color:#1299DA',
40+
'ellipsis' => 'color:#FF8400',
41+
'ns' => 'user-select:none;',
42+
),
43+
'light' => array(
44+
'default' => 'background:none; color:#CC7832; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all',
45+
'num' => 'font-weight:bold; color:#1299DA',
46+
'const' => 'font-weight:bold',
47+
'str' => 'font-weight:bold; color:#629755;',
48+
'note' => 'color:#6897BB',
49+
'ref' => 'color:#6E6E6E',
50+
'public' => 'color:#262626',
51+
'protected' => 'color:#262626',
52+
'private' => 'color:#262626',
53+
'meta' => 'color:#B729D9',
54+
'key' => 'color:#789339',
55+
'index' => 'color:#1299DA',
56+
'ellipsis' => 'color:#CC7832',
57+
'ns' => 'user-select:none;',
58+
),
59+
);
60+
2661
protected $dumpHeader;
2762
protected $dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s">';
2863
protected $dumpSuffix = '</pre><script>Sfdump(%s)</script>';
2964
protected $dumpId = 'sf-dump';
3065
protected $colors = true;
3166
protected $headerIsDumped = false;
3267
protected $lastDepth = -1;
33-
protected $styles = array(
34-
'default' => 'background-color:#18171B; color:#FF8400; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all',
35-
'num' => 'font-weight:bold; color:#1299DA',
36-
'const' => 'font-weight:bold',
37-
'str' => 'font-weight:bold; color:#56DB3A',
38-
'note' => 'color:#1299DA',
39-
'ref' => 'color:#A0A0A0',
40-
'public' => 'color:#FFFFFF',
41-
'protected' => 'color:#FFFFFF',
42-
'private' => 'color:#FFFFFF',
43-
'meta' => 'color:#B729D9',
44-
'key' => 'color:#56DB3A',
45-
'index' => 'color:#1299DA',
46-
'ellipsis' => 'color:#FF8400',
47-
'ns' => 'user-select:none;',
48-
);
68+
protected $styles;
4969

5070
private $displayOptions = array(
5171
'maxDepth' => 1,
@@ -62,6 +82,7 @@ public function __construct($output = null, string $charset = null, int $flags =
6282
AbstractDumper::__construct($output, $charset, $flags);
6383
$this->dumpId = 'sf-dump-'.mt_rand();
6484
$this->displayOptions['fileLinkFormat'] = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
85+
$this->styles = static::$themes['dark'] ?? self::$themes['dark'];
6586
}
6687

6788
/**
@@ -73,6 +94,15 @@ public function setStyles(array $styles)
7394
$this->styles = $styles + $this->styles;
7495
}
7596

97+
public function setTheme(string $themeName)
98+
{
99+
if (!isset(static::$themes[$themeName])) {
100+
throw new \InvalidArgumentException(sprintf('Theme "%s" does not exist in class "%s".', $themeName, static::class));
101+
}
102+
103+
$this->setStyles(static::$themes[$themeName]);
104+
}
105+
76106
/**
77107
* Configures display options.
78108
*

0 commit comments

Comments
 (0)