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

Skip to content

Commit b5526ef

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

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

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

Lines changed: 20 additions & 22 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,7 @@ protected function getDumpHeader()
141137
return $this->dumpHeader;
142138
}
143139

144-
$line = <<<'EOHTML'
140+
$line = str_replace('{$options}', json_encode($this->displayOptions, JSON_FORCE_OBJECT), <<<'EOHTML'
145141
<script>
146142
Sfdump = window.Sfdump || (function (doc) {
147143
@@ -218,13 +214,9 @@ function getLevelNodeForParent(parentNode, currentNode, level) {
218214
return getLevelNodeForParent(parentNode, currentNode, level);
219215
}
220216
221-
return function (root, options) {
217+
return function (root, extraOptions) {
222218
root = doc.getElementById(root);
223-
EOHTML;
224219
225-
$line .= 'options = options || '.json_encode($this->displayOptions).';';
226-
227-
$line .= <<<'EOHTML'
228220
function a(e, f) {
229221
addEventListener(root, e, function (e) {
230222
if ('A' == e.target.tagName) {
@@ -285,6 +277,7 @@ function isCtrlKey(e) {
285277
});
286278
287279
var indentRx = new RegExp('^('+(root.getAttribute('data-indent-pad') || ' ').replace(rxEsc, '\\$1')+')+', 'm'),
280+
options = {$options},
288281
elt = root.getElementsByTagName('A'),
289282
len = elt.length,
290283
i = 0,
@@ -293,6 +286,10 @@ function isCtrlKey(e) {
293286
294287
while (i < len) t.push(elt[i++]);
295288
289+
for (i in extraOptions) {
290+
options[i] = $extraOptions[i];
291+
}
292+
296293
elt = root.getElementsByTagName('SAMP');
297294
len = elt.length;
298295
i = 0;
@@ -378,7 +375,7 @@ function toggleMaxStringLength(elt) {
378375
379376
if (elt.className == 'max-string-length expanded') {
380377
elt.className = 'max-string-length collapsed';
381-
}else{
378+
} else {
382379
elt.className = 'max-string-length expanded';
383380
}
384381
}
@@ -411,15 +408,16 @@ function toggleMaxStringLength(elt) {
411408
outline: none;
412409
}
413410
pre.sf-dump .max-string-length.expanded .collapsed {
414-
display:none;
411+
display: none;
415412
}
416413
pre.sf-dump .max-string-length.collapsed .expanded {
417-
display:none
414+
display: none;
418415
}
419416
pre.sf-dump .max-string-length b {
420417
cursor: pointer;
421418
}
422-
EOHTML;
419+
EOHTML
420+
);
423421

424422
foreach ($this->styles as $class => $style) {
425423
$line .= 'pre.sf-dump'.('default' !== $class ? ' .sf-dump-'.$class : '').'{'.$style.'}';
@@ -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)