Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb51fb66

Browse files
[VarDumper] Handle "title" attribute on virtual properties
1 parentc14fff0 commitb51fb66

File tree

6 files changed

+70
-30
lines changed

6 files changed

+70
-30
lines changed

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

Lines 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‎

Lines 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
break2;
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‎

Lines 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
returnsprintf('<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‎

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespaceSymfony\Component\VarDumper\Tests\Caster;
1313

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

1719
class ExceptionCasterTestextends \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:26
4244
-trace: {
43-
%d. %sExceptionCasterTest.php:23: {
44-
22: {
45-
23: return new \Exception('foo');
46-
24: }
45+
%sExceptionCasterTest.php:26: {
46+
25: {
47+
26: return new \Exception('foo');
48+
27: }
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:26: {
71+
25: {
72+
26: return new \Exception('foo');
73+
27: }
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:26
98100
-trace: {
99-
%d. %sExceptionCasterTest.php:23: {
100-
22: {
101-
23: return new \Exception('foo');
102-
24: }
101+
%sExceptionCasterTest.php:26: {
102+
25: {
103+
26: return new \Exception('foo');
104+
27: }
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:26
126128
-trace: {
127-
%d. %sExceptionCasterTest.php:23
128-
%d. %sExceptionCasterTest.php: %d
129+
%sExceptionCasterTest.php:26
130+
%sExceptionCasterTest.php: %d
129131
%A
130132
EODUMP;
131133

132134
$this->assertDumpMatchesFormat($expectedDump,$e);
133135
}
136+
137+
publicfunctiontestHtmlDump()
138+
{
139+
$e =$this->getTestException(1);
140+
ExceptionCaster::$srcContext = -1;
141+
142+
$h =fopen('php://memory','r+b');
143+
$cloner =newVarCloner();
144+
$cloner->setMaxItems(1);
145+
$dumper =newHtmlDumper($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>26</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>26</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‎

Lines 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‎

Lines 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)

[8]ページ先頭

©2009-2025 Movatter.jp