12
12
namespace Symfony \Component \VarDumper \Dumper ;
13
13
14
14
use Symfony \Component \VarDumper \Cloner \Cursor ;
15
+ use Symfony \Component \VarDumper \Cloner \Data ;
15
16
16
17
/**
17
18
* HtmlDumper dumps variables as HTML.
@@ -23,8 +24,9 @@ class HtmlDumper extends CliDumper
23
24
public static $ defaultOutputStream = 'php://output ' ;
24
25
25
26
protected $ dumpHeader ;
26
- protected $ dumpPrefix = '<pre id=sf-dump > ' ;
27
+ protected $ dumpPrefix = '<pre id=%id% > ' ;
27
28
protected $ dumpSuffix = '</pre><script>Sfjs.dump.instrument()</script> ' ;
29
+ protected $ dumpId = 'sf-dump ' ;
28
30
protected $ colors = true ;
29
31
protected $ headerIsDumped = false ;
30
32
protected $ lastDepth = -1 ;
@@ -82,6 +84,15 @@ public function setDumpBoundaries($prefix, $suffix)
82
84
$ this ->dumpSuffix = $ suffix ;
83
85
}
84
86
87
+ /**
88
+ * {@inheritdoc}
89
+ */
90
+ public function dump (Data $ data , $ lineDumper = null )
91
+ {
92
+ $ this ->dumpId = 'sf-dump- ' .mt_rand ();
93
+ parent ::dump ($ data , $ lineDumper );
94
+ }
95
+
85
96
/**
86
97
* Dumps the HTML header.
87
98
*/
@@ -90,7 +101,7 @@ protected function getDumpHeader()
90
101
$ this ->headerIsDumped = true ;
91
102
92
103
if (null !== $ this ->dumpHeader ) {
93
- return $ this ->dumpHeader ;
104
+ return str_replace ( ' %id% ' , $ this ->dumpId , $ this -> dumpHeader ) ;
94
105
}
95
106
96
107
$ line = <<<'EOHTML'
@@ -129,7 +140,7 @@ protected function getDumpHeader()
129
140
};
130
141
</script>
131
142
<style>
132
- #sf-dump {
143
+ #%id% {
133
144
display: block;
134
145
background-color: #300a24;
135
146
white-space: pre;
@@ -138,31 +149,33 @@ protected function getDumpHeader()
138
149
font: 12px monospace, sans-serif;
139
150
padding: 5px;
140
151
}
141
- #sf-dump span {
152
+ #%id% span {
142
153
display: inline;
143
154
}
144
- #sf-dump .sf-dump-compact {
155
+ #%id% .sf-dump-compact {
145
156
display: none;
146
157
}
147
- #sf-dump abbr {
158
+ #%id% abbr {
148
159
text-decoration: none;
149
160
border: none;
150
161
cursor: help;
151
162
}
152
- #sf-dump a {
163
+ #%id% a {
153
164
text-decoration: none;
154
165
cursor: pointer;
155
166
}
156
- #sf-dump a:hover {
167
+ #%id% a:hover {
157
168
text-decoration: underline;
158
169
}
159
170
EOHTML;
160
171
161
172
foreach ($ this ->styles as $ class => $ style ) {
162
- $ line .= "#sf-dump .sf-dump- $ class { {$ style }} " ;
173
+ $ line .= "#%id% .sf-dump- $ class { {$ style }} " ;
163
174
}
164
175
165
- return $ this ->dumpHeader = preg_replace ('/\s+/ ' , ' ' , $ line ).'</style> ' .$ this ->dumpHeader ;
176
+ $ this ->dumpHeader = preg_replace ('/\s+/ ' , ' ' , $ line ).'</style> ' .$ this ->dumpHeader ;
177
+
178
+ return str_replace ('%id% ' , $ this ->dumpId , $ this ->dumpHeader );
166
179
}
167
180
168
181
/**
@@ -201,9 +214,9 @@ protected function style($style, $val)
201
214
if ('ref ' === $ style ) {
202
215
$ ref = substr ($ val , 1 );
203
216
if ('# ' === $ val [0 ]) {
204
- return "<a class=sf-dump-ref name= \"sf-dump -ref$ ref \"> $ val</a> " ;
217
+ return "<a class=sf-dump-ref name= \"{ $ this -> dumpId } -ref $ ref \"> $ val</a> " ;
205
218
} else {
206
- return "<a class=sf-dump-ref href= \"#sf-dump -ref $ ref \"> $ val</a> " ;
219
+ return "<a class=sf-dump-ref href= \"# { $ this -> dumpId } -ref $ ref \"> $ val</a> " ;
207
220
}
208
221
}
209
222
@@ -236,14 +249,14 @@ protected function dumpLine($depth)
236
249
}
237
250
238
251
if (-1 === $ this ->lastDepth ) {
239
- $ this ->line = $ this ->dumpPrefix .$ this ->line ;
252
+ $ this ->line = str_replace ( ' %id% ' , $ this ->dumpId , $ this -> dumpPrefix ) .$ this ->line ;
240
253
}
241
254
if (!$ this ->headerIsDumped ) {
242
255
$ this ->line = $ this ->getDumpHeader ().$ this ->line ;
243
256
}
244
257
245
258
if (-1 === $ depth ) {
246
- $ this ->line .= $ this ->dumpSuffix ;
259
+ $ this ->line .= str_replace ( ' %id% ' , $ this ->dumpId , $ this -> dumpSuffix ) ;
247
260
parent ::dumpLine (0 );
248
261
}
249
262
$ this ->lastDepth = $ depth ;
0 commit comments