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

Skip to content

Commit bfb9087

Browse files
[VarDumper] Tweak display options implementation
1 parent 0c310c2 commit bfb9087

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ class HtmlDumper extends CliDumper
4646
'str .max-string-length b' => 'color:#A0A0A0',
4747
);
4848

49-
protected $displayOptions = array(
49+
private $displayOptions = array(
5050
'initDepth' => 1,
5151
'maxDepth' => 1,
5252
'maxStringLength' => 160,
5353
);
54-
55-
protected $displayOptionsIsUpdated = false;
54+
private $extraDisplayOptions = array();
5655

5756
/**
5857
* {@inheritdoc}
@@ -87,15 +86,12 @@ public function setStyles(array $styles)
8786
/**
8887
* Configures display options.
8988
*
90-
* @param array $displayOptions A map of displayOptions names to customize the behavior.
89+
* @param array $displayOptions A map of display options to customize the behavior.
9190
*/
9291
public function setDisplayOptions(array $displayOptions)
9392
{
94-
if ($displayOptions)
95-
{
96-
$this->displayOptionsIsUpdated = true;
97-
$this->displayOptions = $displayOptions + $this->displayOptions;
98-
}
93+
$this->headerIsDumped = false;
94+
$this->displayOptions = $displayOptions + $this->displayOptions;
9995
}
10096

10197
/**
@@ -123,9 +119,9 @@ public function setDumpBoundaries($prefix, $suffix)
123119
/**
124120
* {@inheritdoc}
125121
*/
126-
public function dump(Data $data, $output = null, array $displayOptions = [])
122+
public function dump(Data $data, $output = null, array $extraDisplayOptions = array())
127123
{
128-
$this->setDisplayOptions($displayOptions);
124+
$this->extraDisplayOptions = $extraDisplayOptions;
129125
parent::dump($data, $output);
130126
$this->dumpId = 'sf-dump-'.mt_rand();
131127
}
@@ -141,7 +137,8 @@ protected function getDumpHeader()
141137
return $this->dumpHeader;
142138
}
143139

144-
$line = <<<'EOHTML'
140+
$line = json_encode($this->displayOptions, JSON_FORCE_OBJECT);
141+
$line = <<<EOHTML
145142
<script>
146143
Sfdump = window.Sfdump || (function (doc) {
147144
@@ -218,13 +215,9 @@ function getLevelNodeForParent(parentNode, currentNode, level) {
218215
return getLevelNodeForParent(parentNode, currentNode, level);
219216
}
220217
221-
return function (root, options) {
218+
return function (root, extraOptions) {
222219
root = doc.getElementById(root);
223-
EOHTML;
224220
225-
$line .= 'options = options || '.json_encode($this->displayOptions).';';
226-
227-
$line .= <<<'EOHTML'
228221
function a(e, f) {
229222
addEventListener(root, e, function (e) {
230223
if ('A' == e.target.tagName) {
@@ -285,6 +278,7 @@ function isCtrlKey(e) {
285278
});
286279
287280
var indentRx = new RegExp('^('+(root.getAttribute('data-indent-pad') || ' ').replace(rxEsc, '\\$1')+')+', 'm'),
281+
options = {$line},
288282
elt = root.getElementsByTagName('A'),
289283
len = elt.length,
290284
i = 0,
@@ -293,6 +287,10 @@ function isCtrlKey(e) {
293287
294288
while (i < len) t.push(elt[i++]);
295289
290+
for (i in extraOptions) {
291+
options[i] = $extraOptions[i];
292+
}
293+
296294
elt = root.getElementsByTagName('SAMP');
297295
len = elt.length;
298296
i = 0;
@@ -378,7 +376,7 @@ function toggleMaxStringLength(elt) {
378376
379377
if (elt.className == 'max-string-length expanded') {
380378
elt.className = 'max-string-length collapsed';
381-
}else{
379+
} else {
382380
elt.className = 'max-string-length expanded';
383381
}
384382
}
@@ -536,7 +534,7 @@ protected function dumpLine($depth, $endOfValue = false)
536534
$this->line .= sprintf(
537535
$this->dumpSuffix,
538536
$this->dumpId,
539-
$this->displayOptionsIsUpdated ? ','.json_encode($this->displayOptions) : ''
537+
$this->extraDisplayOptions ? ','.json_encode($this->extraDisplayOptions) : ''
540538
);
541539
}
542540
$this->lastDepth = $depth;

0 commit comments

Comments
 (0)