8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ad12251 + 85cb59f commit cc13cc5Copy full SHA for cc13cc5
src/Symfony/Component/VarDumper/Dumper/CliDumper.php
@@ -31,7 +31,6 @@ class CliDumper extends AbstractDumper
31
'num' => '1;38;5;38',
32
'const' => '1;38;5;208',
33
'str' => '1;38;5;113',
34
- 'cchr' => '7',
35
'note' => '38;5;38',
36
'ref' => '38;5;247',
37
'public' => '',
@@ -42,7 +41,15 @@ class CliDumper extends AbstractDumper
42
41
'index' => '38;5;38',
43
);
44
45
- protected static $controlCharsRx = '/[\x00-\x1F\x7F]/';
+ protected static $controlCharsRx = '/[\x00-\x1F\x7F]+/';
+ protected static $controlCharsMap = array(
46
+ "\t" => '\t',
47
+ "\n" => '\n',
48
+ "\v" => '\v',
49
+ "\f" => '\f',
50
+ "\r" => '\r',
51
+ "\033" => '\e',
52
+ );
53
54
/**
55
* {@inheritdoc}
@@ -146,7 +153,7 @@ public function dumpScalar(Cursor $cursor, $type, $value)
146
153
147
154
$this->line .= $this->style($style, $value, $attr);
148
155
149
- $this->dumpLine($cursor->depth);
156
+ $this->dumpLine($cursor->depth, true);
150
157
}
151
158
152
159
@@ -161,13 +168,17 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
161
168
162
169
if ('' === $str) {
163
170
$this->line .= '""';
164
171
165
172
} else {
166
173
$attr = array(
167
- 'length' => function_exists('iconv_strlen') && 0 <= $cut ? iconv_strlen($str, 'UTF-8') + $cut : 0,
174
+ 'length' => 0 <= $cut && function_exists('iconv_strlen') ? iconv_strlen($str, 'UTF-8') + $cut : 0,
175
'binary' => $bin,
176
177
$str = explode("\n", $str);
178
+ if (isset($str[1]) && !isset($str[2]) && !isset($str[1][0])) {
179
+ unset($str[1]);
180
+ $str[0] .= "\n";
181
+ }
182
$m = count($str) - 1;
183
$i = $lineCut = 0;
184
@@ -183,20 +194,30 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
194
195
185
196
foreach ($str as $str) {
197
+ if ($i < $m) {
198
+ $str .= "\n";
199
186
200
if (0 < $this->maxStringWidth && $this->maxStringWidth < $len = iconv_strlen($str, 'UTF-8')) {
187
201
$str = iconv_substr($str, 0, $this->maxStringWidth, 'UTF-8');
188
202
$lineCut = $len - $this->maxStringWidth;
189
203
190
-
191
- if ($m) {
204
+ if ($m && 0 < $cursor->depth) {
192
205
$this->line .= $this->indentPad;
193
206
- $this->line .= $this->style('str', $str, $attr);
207
+ if ('' !== $str) {
208
+ $this->line .= $this->style('str', $str, $attr);
209
210
if ($i++ == $m) {
- $this->line .= '"';
211
if ($m) {
- $this->line .= '""';
212
213
+ $this->dumpLine($cursor->depth);
214
+ if (0 < $cursor->depth) {
215
+ $this->line .= $this->indentPad;
216
217
218
+ $this->line .= '"""';
219
+ } else {
220
+ $this->line .= '"';
221
222
if ($cut < 0) {
223
$this->line .= '…';
@@ -210,7 +231,7 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
231
$lineCut = 0;
232
233
234
+ $this->dumpLine($cursor->depth, $i > $m);
235
236
237
@@ -228,7 +249,7 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
228
249
if (Cursor::HASH_OBJECT === $type) {
229
250
$prefix = 'stdClass' !== $class ? $this->style('note', $class).' {' : '{';
230
251
} elseif (Cursor::HASH_RESOURCE === $type) {
- $prefix = $this->style('note', ':'.$class).' {';
252
+ $prefix = $this->style('note', $class.' resource').($hasChild ? ' {' : ' ');
253
254
$prefix = $class ? $this->style('note', 'array:'.$class).' [' : '[';
255
@@ -237,6 +258,8 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
258
$prefix .= $this->style('ref', (Cursor::HASH_RESOURCE === $type ? '@' : '#').(0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->softRefTo), array('count' => $cursor->softRefCount));
238
259
} elseif ($cursor->hardRefTo && !$cursor->refIndex && $class) {
239
260
$prefix .= $this->style('ref', '&'.$cursor->hardRefTo, array('count' => $cursor->hardRefCount));
261
+ } elseif (!$hasChild && Cursor::HASH_RESOURCE === $type) {
262
+ $prefix = substr($prefix, 0, -1);
240
263
241
264
242
265
$this->line .= $prefix;
@@ -252,8 +275,8 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
275
public function leaveHash(Cursor $cursor, $type, $class, $hasChild, $cut)
276
{
277
$this->dumpEllipsis($cursor, $hasChild, $cut);
- $this->line .= Cursor::HASH_OBJECT === $type || Cursor::HASH_RESOURCE === $type ? '}' : ']';
256
278
+ $this->line .= Cursor::HASH_OBJECT === $type ? '}' : (Cursor::HASH_RESOURCE !== $type ? ']' : ($hasChild ? '}' : ''));
279
257
280
281
282
@@ -360,12 +383,34 @@ protected function style($style, $value, $attr = array())
360
383
361
384
362
385
$style = $this->styles[$style];
363
- $cchr = $this->colors ? "\033[m\033[{$style};{$this->styles['cchr']}m%s\033[m\033[{$style}m" : '%s';
364
- $value = preg_replace_callback(self::$controlCharsRx, function ($r) use ($cchr) {
365
- return sprintf($cchr, "\x7F" === $r[0] ? '?' : chr(64 + ord($r[0])));
366
- }, $value);
367
386
368
- return $this->colors ? sprintf("\033[%sm%s\033[m\033[%sm", $style, $value, $this->styles['default']) : $value;
387
+ $map = static::$controlCharsMap;
388
+ $startCchr = $this->colors ? "\033[m\033[{$this->styles['default']}m" : '';
389
+ $endCchr = $this->colors ? "\033[m\033[{$style}m" : '';
390
+ $value = preg_replace_callback(static::$controlCharsRx, function ($c) use ($map, $startCchr, $endCchr) {
391
+ $s = $startCchr;
392
+ $c = $c[$i = 0];
393
+ do {
394
+ $s .= isset($map[$c[$i]]) ? $map[$c[$i]] : sprintf('\x%02X', ord($c[$i]));
395
+ } while (isset($c[++$i]));
396
+
397
+ return $s.$endCchr;
398
+ }, $value, -1, $cchrCount);
399
400
+ if ($this->colors) {
401
+ if ($cchrCount && "\033" === $value[0]) {
402
+ $value = substr($value, strlen($startCchr));
403
404
+ $value = "\033[{$style}m".$value;
405
406
+ if ($cchrCount && $endCchr === substr($value, -strlen($endCchr))) {
407
+ $value = substr($value, 0, -strlen($endCchr));
408
409
+ $value .= "\033[{$this->styles['default']}m";
410
411
412
413
+ return $value;
369
414
370
415
371
416
@@ -418,7 +463,7 @@ protected function supportsColors()
418
463
419
464
420
465
*/
421
- protected function dumpLine($depth)
466
+ protected function dumpLine($depth, $endOfValue = false)
422
467
423
468
if ($this->colors) {
424
469
$this->line = sprintf("\033[%sm%s\033[m", $this->styles['default'], $this->line);
src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
@@ -35,7 +35,6 @@ class HtmlDumper extends CliDumper
'num' => 'font-weight:bold; color:#1299DA',
'const' => 'font-weight:bold',
'str' => 'font-weight:bold; color:#56DB3A',
38
- 'cchr' => 'color:#FF8400',
39
'note' => 'color:#1299DA',
40
'ref' => 'color:#A0A0A0',
'public' => 'color:#FFFFFF',
@@ -376,10 +375,6 @@ protected function style($style, $value, $attr = array())
376
375
377
378
$v = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
379
- $v = preg_replace_callback(self::$controlCharsRx, function ($r) {
380
- // Use Unicode Control Pictures - see http://www.unicode.org/charts/PDF/U2400.pdf
381
- return sprintf('<span class=sf-dump-cchr title=\\x%02X>&#%d;</span>', ord($r[0]), "\x7F" !== $r[0] ? 0x2400 + ord($r[0]) : 0x2421);
382
- }, $v);
if ('ref' === $style) {
if (empty($attr['count'])) {
@@ -396,25 +391,44 @@ protected function style($style, $value, $attr = array())
$style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property');
} elseif ('str' === $style && 1 < $attr['length']) {
$style .= sprintf(' title="%s%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
- } elseif ('note' === $style) {
- if (false !== $c = strrpos($v, '\\')) {
- return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1));
- } elseif (':' === $v[0]) {
- return sprintf('<abbr title="`%s` resource" class=sf-dump-%s>%s</abbr>', substr($v, 1), $style, $v);
- }
+ } elseif ('note' === $style && false !== $c = strrpos($v, '\\')) {
+ return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1));
} elseif ('protected' === $style) {
$style .= ' title="Protected property"';
} elseif ('private' === $style) {
$style .= sprintf(' title="Private property defined in class: `%s`"', $attr['class']);
- return "<span class=sf-dump-$style>$v</span>";
+ $style = "<span class=sf-dump-{$style}>";
+ $v = preg_replace_callback(static::$controlCharsRx, function ($c) use ($map, $style) {
+ $s = '</span>';
+ return $s.$style;
+ }, $v, -1, $cchrCount);
+ if ($cchrCount && '<' === $v[0]) {
+ $v = substr($v, 7);
417
+ $v = $style.$v;
+ if ($cchrCount && '>' === substr($v, -1)) {
+ $v = substr($v, 0, -strlen($style));
+ $v .= '</span>';
425
+ return $v;
426
427
428
429
430
431
432
433
if (-1 === $this->lastDepth) {
434
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
@@ -65,10 +65,10 @@ class: "Symfony\Component\VarDumper\Tests\CliDumperTest"
65
4 => INF
66
5 => -INF
67
6 => {$intMax}
68
- "str" => "déjà"
69
- 7 => b"é@"
+ "str" => "déjà\\n"
+ 7 => b"é\\x00"
70
"[]" => []
71
- "res" => :stream {@{$res1}
+ "res" => stream resource {@{$res1}
72
wrapper_type: "plainfile"
73
stream_type: "STDIO"
74
mode: "r"
@@ -79,7 +79,7 @@ class: "Symfony\Component\VarDumper\Tests\CliDumperTest"
79
eof: false
80
options: []
81
82
- 8 => :Unknown {@{$res2}}
+ 8 => Unknown resource @{$res2}
83
"obj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo {#%d
84
+foo: "foo"
85
+"bar": "bar"
@@ -126,7 +126,7 @@ public function testXmlResource()
126
127
$this->assertDumpEquals(
128
<<<EOTXT
129
-:xml {
+xml resource {
130
current_byte_index: 0
131
current_column_number: 1
132
current_line_number: 1
@@ -161,7 +161,7 @@ public function testThrowingCaster()
$this->assertStringMatchesFormat(
-:stream {@{$ref}
+stream resource {@{$ref}
wrapper_type: "PHP"
stream_type: "MEMORY"
mode: "w+b"
@@ -192,7 +192,7 @@ public function testThrowingCaster()
public function testRefsInProperties()
$var = (object) array('foo' => 'foo');
- $var->bar =& $var->foo;
+ $var->bar = &$var->foo;
$dumper = new CliDumper();
$dumper->setColors(false);
@@ -343,7 +343,7 @@ private function getSpecialVars()
343
344
$var = function &() {
345
$var = array();
346
- $var[] =& $var;
+ $var[] = &$var;
347
348
return $var;
349
};
src/Symfony/Component/VarDumper/Tests/Fixtures/dumb-var.php
@@ -19,7 +19,7 @@ class DumbFoo
19
$var = array(
20
'number' => 1, null,
21
'const' => 1.1, true, false, NAN, INF, -INF, PHP_INT_MAX,
22
- 'str' => "déjà", "\xE9\x00",
+ 'str' => "déjà\n", "\xE9\x00",
23
'[]' => array(),
24
'res' => $g,
25
$h,
@@ -30,14 +30,14 @@ class DumbFoo
30
$r = array();
-$r[] =& $r;
+$r[] = &$r;
-$var['recurs'] =& $r;
-$var[] =& $var[0];
+$var['recurs'] = &$r;
+$var[] = &$var[0];
$var['sobj'] = $var['obj'];
-$var['snobj'] =& $var['nobj'][0];
+$var['snobj'] = &$var['nobj'][0];
$var['snobj2'] = $var['nobj'][0];
$var['file'] = __FILE__;
-$var["bin-key-\xE9"] = "";
+$var["bin-key-\xE9"] = '';
unset($g, $h, $r);
src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
@@ -68,10 +68,10 @@ public function testGet()
<span class=sf-dump-key>4</span> => <span class=sf-dump-num>INF</span>
<span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
- "<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="4 characters">déjà</span>"
- <span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">é<span class=sf-dump-cchr title=\\x00>␀</span></span>"
+ "<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="5 characters">déjà</span>\\n"
+ <span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">é</span>\\x00"
"<span class=sf-dump-key>[]</span>" => []
- "<span class=sf-dump-key>res</span>" => <abbr title="`stream` resource" class=sf-dump-note>:stream</abbr> {<a class=sf-dump-ref>@{$res1}</a><samp>
+ "<span class=sf-dump-key>res</span>" => <span class=sf-dump-note>stream resource</span> <a class=sf-dump-ref>@{$res1}</a><samp>
75
<span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
76
<span class=sf-dump-meta>stream_type</span>: "<span class=sf-dump-str title="5 characters">STDIO</span>"
77
<span class=sf-dump-meta>mode</span>: "<span class=sf-dump-str>r</span>"
@@ -82,7 +82,7 @@ public function testGet()
<span class=sf-dump-meta>eof</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>options</span>: []
</samp>}
- <span class=sf-dump-key>8</span> => <abbr title="`Unknown` resource" class=sf-dump-note>:Unknown</abbr> {<a class=sf-dump-ref>@{$res2}</a>}
+ <span class=sf-dump-key>8</span> => <span class=sf-dump-note>Unknown resource</span> <a class=sf-dump-ref>@{$res2}</a>
86
"<span class=sf-dump-key>obj</span>" => <abbr title="Symfony\Component\VarDumper\Tests\Fixture\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a><samp id={$dumpId}-ref2%d>
87
+<span class=sf-dump-public title="Public property">foo</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
88
+"<span class=sf-dump-public title="Runtime added dynamic property">bar</span>": "<span class=sf-dump-str title="3 characters">bar</span>"