Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8ec15d0

Browse filesBrowse files
[VarDumper] add force-collapse/expand + use it for traces
1 parent 481e31c commit 8ec15d0
Copy full SHA for 8ec15d0

File tree

6 files changed

+72
-15
lines changed
Filter options

6 files changed

+72
-15
lines changed

‎src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
+16-6Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
127127
}
128128
$lastCall = isset($frames[$i]['function']) ? (isset($frames[$i]['class']) ? $frames[0]['class'].$frames[$i]['type'] : '').$frames[$i]['function'].'()' : '';
129129
$frames[] = array('function' => '');
130+
$collapse = false;
130131

131132
for ($j += $trace->numberingOffset - $i++; isset($frames[$i]); ++$i, --$j) {
132133
$f = $frames[$i];
@@ -145,6 +146,13 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
145146
$f = self::castFrameStub($frame, array(), $frame, true);
146147
if (isset($f[$prefix.'src'])) {
147148
foreach ($f[$prefix.'src']->value as $label => $frame) {
149+
if (0 === strpos($label, "\0~collapse=0")) {
150+
if ($collapse) {
151+
$label = substr_replace($label, '1', 11, 1);
152+
} else {
153+
$collapse = true;
154+
}
155+
}
148156
$label = substr_replace($label, "title=Stack level $j.&", 2, 0);
149157
}
150158
$f = $frames[$i - 1];
@@ -162,7 +170,7 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
162170
} else {
163171
$label = substr_replace($prefix, "title=Stack level $j.", 2, 0).$lastCall;
164172
}
165-
$a[$label] = $frame;
173+
$a[substr_replace($label, 'separator= &', 2, 0)] = $frame;
166174

167175
$lastCall = $call;
168176
}
@@ -197,9 +205,10 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
197205
$caller = isset($f['function']) ? sprintf('in %s() on line %d', (isset($f['class']) ? $f['class'].$f['type'] : '').$f['function'], $f['line']) : null;
198206
$src = $f['line'];
199207
$srcKey = $f['file'];
200-
$ellipsis = (new LinkStub($srcKey, 0))->attr;
201-
$ellipsisTail = isset($ellipsis['ellipsis-tail']) ? $ellipsis['ellipsis-tail'] : 0;
202-
$ellipsis = isset($ellipsis['ellipsis']) ? $ellipsis['ellipsis'] : 0;
208+
$ellipsis = new LinkStub($srcKey, 0);
209+
$inVendor = $ellipsis->inVendor;
210+
$ellipsisTail = isset($ellipsis->attr['ellipsis-tail']) ? $ellipsis->attr['ellipsis-tail'] : 0;
211+
$ellipsis = isset($ellipsis->attr['ellipsis']) ? $ellipsis->attr['ellipsis'] : 0;
203212

204213
if (file_exists($f['file']) && 0 <= self::$srcContext) {
205214
if (!empty($f['class']) && (is_subclass_of($f['class'], 'Twig\Template') || is_subclass_of($f['class'], 'Twig_Template')) && method_exists($f['class'], 'getDebugInfo')) {
@@ -226,7 +235,8 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
226235
}
227236
}
228237
}
229-
$srcAttr = $ellipsis ? 'ellipsis-type=path&ellipsis='.$ellipsis.'&ellipsis-tail='.$ellipsisTail : '';
238+
$srcAttr = 'collapse='.(int) $inVendor;
239+
$srcAttr .= $ellipsis ? '&ellipsis-type=path&ellipsis='.$ellipsis.'&ellipsis-tail='.$ellipsisTail : '';
230240
self::$framesCache[$cacheKey] = $a[$prefix.'src'] = new EnumStub(array("\0~$srcAttr\0$srcKey" => $src));
231241
}
232242
}
@@ -329,7 +339,7 @@ private static function extractSource($srcLines, $line, $srcContext, $title, $la
329339
}
330340
}
331341
$c->attr['lang'] = $lang;
332-
$srcLines[sprintf("\0~%d\0", $i + $line - $srcContext)] = $c;
342+
$srcLines[sprintf("\0~separator=› &%d\0", $i + $line - $srcContext)] = $c;
333343
}
334344

335345
return new EnumStub($srcLines);

‎src/Symfony/Component/VarDumper/Caster/LinkStub.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/LinkStub.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
class LinkStub extends ConstStub
2020
{
21+
public $inVendor = false;
22+
2123
private static $vendorRoots;
2224
private static $composerRoots;
2325

@@ -50,10 +52,10 @@ public function __construct($label, $line = 0, $href = null)
5052
if ($label !== $this->attr['file'] = realpath($href) ?: $href) {
5153
return;
5254
}
53-
if ($composerRoot = $this->getComposerRoot($href, $inVendor)) {
55+
if ($composerRoot = $this->getComposerRoot($href, $this->inVendor)) {
5456
$this->attr['ellipsis'] = strlen($href) - strlen($composerRoot) + 1;
5557
$this->attr['ellipsis-type'] = 'path';
56-
$this->attr['ellipsis-tail'] = 1 + ($inVendor ? 2 + strlen(implode(array_slice(explode(DIRECTORY_SEPARATOR, substr($href, 1 - $this->attr['ellipsis'])), 0, 2))) : 0);
58+
$this->attr['ellipsis-tail'] = 1 + ($this->inVendor ? 2 + strlen(implode(array_slice(explode(DIRECTORY_SEPARATOR, substr($href, 1 - $this->attr['ellipsis'])), 0, 2))) : 0);
5759
} elseif (3 < count($ellipsis = explode(DIRECTORY_SEPARATOR, $href))) {
5860
$this->attr['ellipsis'] = 2 + strlen(implode(array_slice($ellipsis, -2)));
5961
$this->attr['ellipsis-type'] = 'path';

‎src/Symfony/Component/VarDumper/Cloner/Cursor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/Cursor.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ class Cursor
3939
public $hashCut = 0;
4040
public $stop = false;
4141
public $attr = array();
42+
public $skipChildren = false;
4243
}

‎src/Symfony/Component/VarDumper/Cloner/Data.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/Data.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,16 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
355355
$withChildren = $children && $cursor->depth !== $this->maxDepth && $this->maxItemsPerDepth;
356356
$dumper->enterHash($cursor, $item->type, $item->class, $withChildren);
357357
if ($withChildren) {
358-
$cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class);
358+
if ($cursor->skipChildren) {
359+
$withChildren = false;
360+
$cut = -1;
361+
} else {
362+
$cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class);
363+
}
359364
} elseif ($children && 0 <= $cut) {
360365
$cut += count($children);
361366
}
367+
$cursor->skipChildren = false;
362368
$dumper->leaveHash($cursor, $item->type, $item->class, $withChildren, $cut);
363369
break;
364370

‎src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class CliDumper extends AbstractDumper
5151
"\033" => '\e',
5252
);
5353

54+
protected $collapseNextHash = false;
55+
protected $expandNextHash = false;
56+
5457
/**
5558
* {@inheritdoc}
5659
*/
@@ -253,6 +256,11 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
253256
{
254257
$this->dumpKey($cursor);
255258

259+
if ($this->collapseNextHash) {
260+
$cursor->skipChildren = true;
261+
$this->collapseNextHash = $hasChild = false;
262+
}
263+
256264
$class = $this->utf8Encode($class);
257265
if (Cursor::HASH_OBJECT === $type) {
258266
$prefix = $class && 'stdClass' !== $class ? $this->style('note', $class).' {' : '{';
@@ -368,7 +376,15 @@ protected function dumpKey(Cursor $cursor)
368376
break;
369377
}
370378

371-
$this->line .= $bin.$this->style($style, $key[1], $attr).': ';
379+
if (isset($attr['collapse'])) {
380+
if ($attr['collapse']) {
381+
$this->collapseNextHash = true;
382+
} else {
383+
$this->expandNextHash = true;
384+
}
385+
}
386+
387+
$this->line .= $bin.$this->style($style, $key[1], $attr).(isset($attr['separator']) ? $attr['separator'] : ': ');
372388
} else {
373389
// This case should not happen
374390
$this->line .= '-'.$bin.'"'.$this->style('private', $key, array('class' => '')).'": ';
@@ -397,6 +413,18 @@ protected function style($style, $value, $attr = array())
397413
$this->colors = $this->supportsColors();
398414
}
399415

416+
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
417+
$prefix = 'path' === $attr['ellipsis-type'] ? '' : substr($value, 0, -$attr['ellipsis']);
418+
if (!empty($attr['ellipsis-tail'])) {
419+
$prefix .= substr($value, -$attr['ellipsis'], $attr['ellipsis-tail']);
420+
$value = substr($value, -$attr['ellipsis'] + $attr['ellipsis-tail']);
421+
} else {
422+
$value = substr($value, -$attr['ellipsis']);
423+
}
424+
425+
return $this->style('default', $prefix).$this->style($style, $value);
426+
}
427+
400428
$style = $this->styles[$style];
401429

402430
$map = static::$controlCharsMap;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ function xpathString(str) {
366366
for (i = 0; i < len; ++i) {
367367
elt = t[i];
368368
if ('SAMP' == elt.tagName) {
369-
elt.className = 'sf-dump-expanded';
370369
a = elt.previousSibling || {};
371370
if ('A' != a.tagName) {
372371
a = doc.createElement('A');
@@ -383,7 +382,8 @@ function xpathString(str) {
383382
x += elt.parentNode.getAttribute('data-depth')/1;
384383
}
385384
elt.setAttribute('data-depth', x);
386-
if (x > options.maxDepth) {
385+
if (elt.className ? 'sf-dump-expanded' !== elt.className : (x > options.maxDepth)) {
386+
elt.className = 'sf-dump-expanded';
387387
toggle(a);
388388
}
389389
} else if ('sf-dump-ref' == elt.className && (a = elt.getAttribute('href'))) {
@@ -728,15 +728,25 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
728728
{
729729
parent::enterHash($cursor, $type, $class, false);
730730

731+
if ($cursor->skipChildren) {
732+
$cursor->skipChildren = false;
733+
$eol = ' class=sf-dump-compact>';
734+
} elseif ($this->expandNextHash) {
735+
$this->expandNextHash = false;
736+
$eol = ' class=sf-dump-expanded>';
737+
} else {
738+
$eol = '>';
739+
}
740+
731741
if ($hasChild) {
742+
$this->line .= '<samp';
732743
if ($cursor->refIndex) {
733744
$r = Cursor::HASH_OBJECT !== $type ? 1 - (Cursor::HASH_RESOURCE !== $type) : 2;
734745
$r .= $r && 0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->refIndex;
735746

736-
$this->line .= sprintf('<samp id=%s-ref%s>', $this->dumpId, $r);
737-
} else {
738-
$this->line .= '<samp>';
747+
$this->line .= sprintf(' id=%s-ref%s', $this->dumpId, $r);
739748
}
749+
$this->line .= $eol;
740750
$this->dumpLine($cursor->depth);
741751
}
742752
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.