26
26
class DumpDataCollector extends DataCollector implements DataDumperInterface
27
27
{
28
28
private $ stopwatch ;
29
+ private $ dataCount = 0 ;
29
30
private $ isCollected = true ;
30
- private $ clonesRoot ;
31
31
private $ clonesCount = 0 ;
32
+ private $ clonesIndex = 0 ;
33
+ private $ rootRefs ;
32
34
33
35
public function __construct (Stopwatch $ stopwatch = null )
34
36
{
35
37
$ this ->stopwatch = $ stopwatch ;
36
- $ this ->clonesRoot = $ this ;
38
+
39
+ // All clones share these properties by reference:
40
+ $ this ->rootRefs = array (
41
+ &$ this ->data ,
42
+ &$ this ->dataCount ,
43
+ &$ this ->isCollected ,
44
+ &$ this ->clonesCount ,
45
+ );
37
46
}
38
47
39
48
public function __clone ()
40
49
{
41
- $ this ->data = array ();
42
- $ this ->clonesRoot ->clonesCount ++;
50
+ $ this ->clonesIndex = ++$ this ->clonesCount ;
43
51
}
44
52
45
53
public function dump (Data $ data )
46
54
{
47
55
if ($ this ->stopwatch ) {
48
56
$ this ->stopwatch ->start ('dump ' );
49
57
}
50
- if ($ this ->clonesRoot -><
8000
span class=pl-c1>isCollected) {
51
- $ this ->clonesRoot ->isCollected = false ;
52
- register_shutdown_function (array ($ this ->clonesRoot , 'flushDumps ' ));
58
+ if ($ this ->isCollected ) {
59
+ $ this ->isCollected = false ;
53
60
}
54
61
55
62
$ trace = PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS : true ;
@@ -66,7 +73,7 @@ public function dump(Data $data)
66
73
67
74
for ($ i = 1 ; $ i < 7 ; ++$ i ) {
68
75
if (isset ($ trace [$ i ]['class ' ], $ trace [$ i ]['function ' ])
69
- && 'dump ' === $ trace [$ i ]['function ' ]
76
+ && ( 'dump ' === $ trace [$ i ]['function ' ] || ' debug ' === $ trace [ $ i ][ ' function ' ])
70
77
&& 'Symfony\Component\VarDumper\VarDumper ' === $ trace [$ i ]['class ' ]
71
78
) {
72
79
$ file = $ trace [$ i ]['file ' ];
@@ -107,7 +114,8 @@ public function dump(Data $data)
107
114
$ name = substr ($ file , strrpos ($ file , '/ ' ) + 1 );
108
115
}
109
116
110
- $ this ->clonesRoot ->data [] = compact ('data ' , 'name ' , 'file ' , 'line ' , 'fileExcerpt ' );
117
+ $ this ->data [] = compact ('data ' , 'name ' , 'file ' , 'line ' , 'fileExcerpt ' );
118
+ ++$ this ->dataCount ;
111
119
112
120
if ($ this ->stopwatch ) {
113
121
$ this ->stopwatch ->stop ('dump ' );
@@ -120,23 +128,28 @@ public function collect(Request $request, Response $response, \Exception $except
120
128
121
129
public function serialize ()
122
130
{
123
- $ ser = serialize ($ this ->clonesRoot ->data );
124
- $ this ->clonesRoot ->data = array ();
125
- $ this ->clonesRoot ->isCollected = true ;
131
+ if ($ this ->clonesCount !== $ this ->clonesIndex ) {
132
+ return 'a:0:{} ' ;
133
+ }
134
+
135
+ $ ser = serialize ($ this ->data );
136
+ $ this ->data = array ();
137
+ $ this ->dataCount = 0 ;
138
+ $ this ->isCollected = true ;
126
139
127
140
return $ ser ;
128
141
}
129
142
130
143
public function unserialize ($ data )
131
144
{
132
145
parent ::unserialize ($ data );
133
-
134
- $ this ->clonesRoot = $ this ;
146
+ $ this -> dataCount = count ( $ this -> data );
147
+ self :: __construct ( $ this ->stopwatch ) ;
135
148
}
136
149
137
150
public function getDumpsCount ()
138
151
{
139
- return count ( $ this ->clonesRoot -> data ) ;
152
+ return $ this ->dataCount ;
140
153
}
141
154
142
155
public function getDumpsExcerpts ()
@@ -193,7 +206,7 @@ public function getDumps($getData = false)
193
206
}
194
207
$ dumps = array ();
195
208
196
- foreach ($ this ->clonesRoot -> data as $ dump ) {
209
+ foreach ($ this ->data as $ dump ) {
197
210
$ json = '' ;
198
211
if ($ getData ) {
199
212
$ dumper ->dump ($ dump ['data ' ], function ($ line ) use (&$ json ) {$ json .= $ line ;});
@@ -210,11 +223,11 @@ public function getName()
210
223
return 'dump ' ;
211
224
}
212
225
213
- public function flushDumps ()
226
+ public function __destruct ()
214
227
{
215
- if (0 === $ this ->clonesRoot -> clonesCount -- && !$ this ->clonesRoot -> isCollected && $ this -> clonesRoot ->data ) {
216
- $ this ->clonesRoot -> clonesCount = 0 ;
217
- $ this ->clonesRoot -> isCollected = true ;
228
+ if (0 === $ this ->clonesCount -- && !$ this ->isCollected && $ this ->data ) {
229
+ $ this ->clonesCount = 0 ;
230
+ $ this ->isCollected = true ;
218
231
219
232
$ h = headers_list ();
220
233
$ i = count ($ h );
@@ -223,31 +236,32 @@ public function flushDumps()
223
236
--$ i ;
224
237
}
225
238
226
- if (stripos ($ h [$ i ], 'html ' )) {
239
+ if (' cli ' !== PHP_SAPI && stripos ($ h [$ i ], 'html ' )) {
227
240
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> ' ;
228
- $ dumper = new HtmlDumper ();
241
+ $ dumper = new HtmlDumper (' php://output ' );
229
242
} else {
230
- $ dumper = new CliDumper ();
243
+ $ dumper = new CliDumper (' php://output ' );
231
244
$ dumper ->setColors (false );
232
245
}
233
246
234
- foreach ($ this ->clonesRoot -> data as $ i => $ dump ) {
235
- $ this ->clonesRoot -> data [$ i ] = null ;
247
+ foreach ($ this ->data as $ i => $ dump ) {
248
+ $ this ->data [$ i ] = null ;
236
249
237
250
if ($ dumper instanceof HtmlDumper) {
238
251
$ dump ['name ' ] = htmlspecialchars ($ dump ['name ' ], ENT_QUOTES , 'UTF-8 ' );
239
252
$ dump ['file ' ] = htmlspecialchars ($ dump ['file ' ], ENT_QUOTES , 'UTF-8 ' );
240
253
if ('' !== $ dump ['file ' ]) {
241
254
$ dump ['name ' ] = "<abbr title= \"{$ dump ['file ' ]}\"> {$ dump ['name ' ]}</abbr> " ;
242
255
}
243
- echo "\n<br>< span class= \"sf-dump-meta \">in {$ dump ['name ' ]} on line {$ dump ['line ' ]}:</span> " ;
256
+ echo "\n<span class= \"sf-dump-meta \"> {$ dump ['name ' ]} on line {$ dump ['line ' ]}:</span> " ;
244
257
} else {
245
- echo "\n in {$ dump ['name ' ]} on line {$ dump ['line ' ]}: \n \n" ;
258
+ echo "{$ dump ['name ' ]} on line {$ dump ['line ' ]}: \n" ;
246
259
}
247
260
$ dumper ->dump ($ dump ['data ' ]);
248
261
}
249
262
250
- $ this ->clonesRoot ->data = array ();
263
+ $ this ->data = array ();
264
+ $ this ->dataCount = 0 ;
251
265
}
252
266
}
253
267
}
0 commit comments