@@ -46,13 +46,12 @@ class HtmlDumper extends CliDumper
46
46
'str .max-string-length b ' => 'color:#A0A0A0 ' ,
47
47
);
48
48
49
- protected $ displayOptions = array (
49
+ private $ displayOptions = array (
50
50
'initDepth ' => 1 ,
51
51
'maxDepth ' => 1 ,
52
52
'maxStringLength ' => 160 ,
53
53
);
54
-
55
- protected $ displayOptionsIsUpdated = false ;
54
+ private $ extraDisplayOptions = array ();
56
55
57
56
/**
58
57
* {@inheritdoc}
@@ -87,15 +86,12 @@ public function setStyles(array $styles)
87
86
/**
88
87
* Configures display options.
89
88
*
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.
91
90
*/
92
91
public function setDisplayOptions (array $ displayOptions )
93
92
{
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 ;
99
95
}
100
96
101
97
/**
@@ -123,9 +119,9 @@ public function setDumpBoundaries($prefix, $suffix)
123
119
/**
124
120
* {@inheritdoc}
125
121
*/
126
- public function dump (Data $ data , $ output = null , array $ displayOptions = [] )
122
+ public function dump (Data $ data , $ output = null , array $ extraDisplayOptions = array () )
127
123
{
128
- $ this ->setDisplayOptions ( $ displayOptions ) ;
124
+ $ this ->extraDisplayOptions = $ extraDisplayOptions ;
129
125
parent ::dump ($ data , $ output );
130
126
$ this ->dumpId = 'sf-dump- ' .mt_rand ();
131
127
}
@@ -141,7 +137,7 @@ protected function getDumpHeader()
141
137
return $ this ->dumpHeader ;
142
138
}
143
139
144
- $ line = <<<'EOHTML'
140
+ $ line = str_replace ( ' {$options} ' , json_encode ( $ this -> displayOptions , JSON_FORCE_OBJECT ), <<<'EOHTML'
145
141
<script>
146
142
Sfdump = window.Sfdump || (function (doc) {
147
143
@@ -218,13 +214,9 @@ function getLevelNodeForParent(parentNode, currentNode, level) {
218
214
return getLevelNodeForParent(parentNode, currentNode, level);
219
215
}
220
216
221
- return function (root, options ) {
217
+ return function (root, extraOptions ) {
222
218
root = doc.getElementById(root);
223
- EOHTML;
224
219
225
- $ line .= 'options = options || ' .json_encode ($ this ->displayOptions ).'; ' ;
226
-
227
- $ line .= <<<'EOHTML'
228
220
function a(e, f) {
229
221
addEventListener(root, e, function (e) {
230
222
if ('A' == e.target.tagName) {
@@ -285,6 +277,7 @@ function isCtrlKey(e) {
285
277
});
286
278
287
279
var indentRx = new RegExp('^('+(root.getAttribute('data-indent-pad') || ' ').replace(rxEsc, '\\$1')+')+', 'm'),
280
+ options = {$options},
288
281
elt = root.getElementsByTagName('A'),
289
282
len = elt.length,
290
283
i = 0,
@@ -293,6 +286,10 @@ function isCtrlKey(e) {
293
286
294
287
while (i < len) t.push(elt[i++]);
295
288
289
+ for (i in extraOptions) {
290
+ options[i] = $extraOptions[i];
291
+ }
292
+
296
293
elt = root.getElementsByTagName('SAMP');
297
294
len = elt.length;
298
295
i = 0;
@@ -378,7 +375,7 @@ function toggleMaxStringLength(elt) {
378
375
379
376
if (elt.className == 'max-string-length expanded') {
380
377
elt.className = 'max-string-length collapsed';
381
- }else{
378
+ } else {
382
379
elt.className = 'max-string-length expanded';
383
380
}
384
381
}
@@ -411,15 +408,16 @@ function toggleMaxStringLength(elt) {
411
408
outline: none;
412
409
}
413
410
pre.sf-dump .max-string-length.expanded .collapsed {
414
- display:none;
411
+ display: none;
415
412
}
416
413
pre.sf-dump .max-string-length.collapsed .expanded {
417
- display:none
414
+ display: none;
418
415
}
419
416
pre.sf-dump .max-string-length b {
420
417
cursor: pointer;
421
418
}
422
- EOHTML;
419
+ EOHTML
420
+ );
423
421
424
422
foreach ($ this ->styles as $ class => $ style ) {
425
423
$ line .= 'pre.sf-dump ' .('default ' !== $ class ? ' .sf-dump- ' .$ class : '' ).'{ ' .$ style .'} ' ;
@@ -536,7 +534,7 @@ protected function dumpLine($depth, $endOfValue = false)
536
534
$ this ->line .= sprintf (
537
535
$ this ->dumpSuffix ,
538
536
$ this ->dumpId ,
539
- $ this ->displayOptionsIsUpdated ? ', ' .json_encode ($ this ->displayOptions ) : ''
537
+ $ this ->extraDisplayOptions ? ', ' .json_encode ($ this ->extraDisplayOptions ) : ''
540
538
);
541
539
}
542
540
$ this ->lastDepth = $ depth ;
0 commit comments