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 865f344

Browse filesBrowse files
committed
feature #19714 [VarDumper] Handle "title" attribute on virtual properties (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- [VarDumper] Handle "title" attribute on virtual properties | Q | A | ------------- | --- | Branch? | master | New feature? | yes | Tests pass? | yes | License | MIT As seen with @wouterj , it would be better to *not* display the stack level in front of each stack line. This PR does just that, and moves the stack level to a title attribute in HtmlDumper. ![capture du 2016-08-23 14-09-43](https://cloud.githubusercontent.com/assets/243674/17891395/cc40b088-693b-11e6-8523-89ff51be929a.png) Commits ------- 19bcf63 [VarDumper] Handle "title" attribute on virtual properties
2 parents f5f1e10 + 19bcf63 commit 865f344
Copy full SHA for 865f344

File tree

6 files changed

+70
-30
lines changed
Filter options

6 files changed

+70
-30
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
8989
$stub->handle = 0;
9090
$frames = $trace->value;
9191
$prefix = Caster::PREFIX_VIRTUAL;
92+
$format = "\0~Stack level %s.\0%s";
9293

9394
$a = array();
9495
$j = count($frames);
@@ -124,7 +125,7 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
124125
$frame->value['args'] = $f[$prefix.'args'];
125126
}
126127
}
127-
$a[$prefix.$j.'. '.$label] = $frame;
128+
$a[sprintf($format, $j, $label)] = $frame;
128129

129130
$lastCall = ' ==> '.$call;
130131
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,16 @@ protected function dumpKey(Cursor $cursor)
342342
} elseif (0 < strpos($key, "\0", 1)) {
343343
$key = explode("\0", substr($key, 1), 2);
344344

345-
switch ($key[0]) {
345+
switch ($key[0][0]) {
346346
case '+': // User inserted keys
347347
$attr['dynamic'] = true;
348348
$this->line .= '+'.$bin.'"'.$this->style('public', $key[1], $attr).'": ';
349349
break 2;
350350
case '~':
351351
$style = 'meta';
352+
if (isset($key[0][1])) {
353+
$attr['title'] = substr($key[0], 1);
354+
}
352355
break;
353356
case '*':
354357
$style = 'protected';

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ protected function style($style, $value, $attr = array())
445445
return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1));
446446
} elseif ('protected' === $style) {
447447
$style .= ' title="Protected property"';
448+
} elseif ('meta' === $style && isset($attr['title'])) {
449+
$style .= sprintf(' title="%s"', htmlspecialchars($attr['title'], ENT_QUOTES, 'UTF-8'));
448450
} elseif ('private' === $style) {
449451
$style .= sprintf(' title="Private property defined in class:&#10;`%s`"', $attr['class']);
450452
}

‎src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php
+54-20Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

1414
use Symfony\Component\VarDumper\Caster\ExceptionCaster;
15+
use Symfony\Component\VarDumper\Cloner\VarCloner;
16+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
1517
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1618

1719
class ExceptionCasterTest extends \PHPUnit_Framework_TestCase
@@ -38,14 +40,14 @@ public function testDefaultSettings()
3840
#message: "foo"
3941
#code: 0
4042
#file: "%sExceptionCasterTest.php"
41-
#line: 23
43+
#line: 25
4244
-trace: {
43-
%d. %sExceptionCasterTest.php:23: {
44-
22: {
45-
23: return new \Exception('foo');
46-
24: }
45+
%sExceptionCasterTest.php:25: {
46+
24: {
47+
25: return new \Exception('foo');
48+
26: }
4749
}
48-
%d. %sExceptionCasterTest.php:%d: {
50+
%sExceptionCasterTest.php:%d: {
4951
%d: {
5052
%d: $e = $this->getTestException(1);
5153
%d:
@@ -65,12 +67,12 @@ public function testSeek()
6567

6668
$expectedDump = <<<'EODUMP'
6769
{
68-
%d. %sExceptionCasterTest.php:23: {
69-
22: {
70-
23: return new \Exception('foo');
71-
24: }
70+
%sExceptionCasterTest.php:25: {
71+
24: {
72+
25: return new \Exception('foo');
73+
26: }
7274
}
73-
%d. %sExceptionCasterTest.php:%d: {
75+
%sExceptionCasterTest.php:%d: {
7476
%d: {
7577
%d: $e = $this->getTestException(2);
7678
%d:
@@ -94,14 +96,14 @@ public function testNoArgs()
9496
#message: "foo"
9597
#code: 0
9698
#file: "%sExceptionCasterTest.php"
97-
#line: 23
99+
#line: 25
98100
-trace: {
99-
%d. %sExceptionCasterTest.php:23: {
100-
22: {
101-
23: return new \Exception('foo');
102-
24: }
101+
%sExceptionCasterTest.php:25: {
102+
24: {
103+
25: return new \Exception('foo');
104+
26: }
103105
}
104-
%d. %sExceptionCasterTest.php:%d: {
106+
%sExceptionCasterTest.php:%d: {
105107
%d: {
106108
%d: $e = $this->getTestException(1);
107109
%d: ExceptionCaster::$traceArgs = false;
@@ -122,13 +124,45 @@ public function testNoSrcContext()
122124
#message: "foo"
123125
#code: 0
124126
#file: "%sExceptionCasterTest.php"
125-
#line: 23
127+
#line: 25
126128
-trace: {
127-
%d. %sExceptionCasterTest.php: 23
128-
%d. %sExceptionCasterTest.php: %d
129+
%sExceptionCasterTest.php: 25
130+
%sExceptionCasterTest.php: %d
129131
%A
130132
EODUMP;
131133

132134
$this->assertDumpMatchesFormat($expectedDump, $e);
133135
}
136+
137+
public function testHtmlDump()
138+
{
139+
$e = $this->getTestException(1);
140+
ExceptionCaster::$srcContext = -1;
141+
142+
$h = fopen('php://memory', 'r+b');
143+
$cloner = new VarCloner();
144+
$cloner->setMaxItems(1);
145+
$dumper = new HtmlDumper($h);
146+
$dumper->setDumpHeader('<foo></foo>');
147+
$dumper->setDumpBoundaries('<bar>', '</bar>');
148+
$dumper->dump($cloner->cloneVar($e)->withRefHandles(false));
149+
$dump = stream_get_contents($h, -1, 0);
150+
fclose($h);
151+
152+
$expectedDump = <<<'EODUMP'
153+
<foo></foo><bar><span class=sf-dump-note>Exception</span> {<samp>
154+
#<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
155+
#<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span>
156+
#<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%d characters">%sExceptionCasterTest.php</span>"
157+
#<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>25</span>
158+
-<span class=sf-dump-private title="Private property defined in class:&#10;`Exception`">trace</span>: {<samp>
159+
<span class=sf-dump-meta title="Stack level %d.">%sExceptionCasterTest.php</span>: <span class=sf-dump-num>25</span>
160+
&hellip;12
161+
</samp>}
162+
</samp>}
163+
</bar>
164+
EODUMP;
165+
166+
$this->assertStringMatchesFormat($expectedDump, $dump);
167+
}
134168
}

‎src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,17 @@ public function testGenerator()
177177
0 => ReflectionGenerator {
178178
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
179179
trace: {
180-
3. %sGeneratorDemo.php:9: {
180+
%sGeneratorDemo.php:9: {
181181
8: {
182182
9: yield 1;
183183
10: }
184184
}
185-
2. %sGeneratorDemo.php:20: {
185+
%sGeneratorDemo.php:20: {
186186
19: {
187187
20: yield from GeneratorDemo::foo();
188188
21: }
189189
}
190-
1. %sGeneratorDemo.php:14: {
190+
%sGeneratorDemo.php:14: {
191191
13: {
192192
14: yield from bar();
193193
15: }

‎src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,23 @@ public function testThrowingCaster()
288288
⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {{$r}
289289
#message: "Unexpected Exception thrown from a caster: Foobar"
290290
-trace: {
291-
%d. {$twig}
292-
%d. %sTemplate.php:%d: {
291+
{$twig}
292+
%sTemplate.php:%d: {
293293
%d: try {
294294
%d: \$this->doDisplay(\$context, \$blocks);
295295
%d: } catch (Twig_Error \$e) {
296296
}
297-
%d. %sTemplate.php:%d: {
297+
%sTemplate.php:%d: {
298298
%d: {
299299
%d: \$this->displayWithErrorHandling(\$this->env->mergeGlobals(\$context), array_merge(\$this->blocks, \$blocks));
300300
%d: }
301301
}
302-
%d. %sTemplate.php:%d: {
302+
%sTemplate.php:%d: {
303303
%d: try {
304304
%d: \$this->display(\$context);
305305
%d: } catch (Exception \$e) {
306306
}
307-
%d. %sCliDumperTest.php:{$line}: {
307+
%sCliDumperTest.php:{$line}: {
308308
%d: }
309309
{$line}: };'),
310310
%d: ));

0 commit comments

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