Skip to content

Commit f2cd3f0

Browse files
Merge branch '4.4'
* 4.4: (39 commits) [Console] Fix #33915, Detect dimensions using mode CON if vt100 is supported [PhpUnitBridge] Also search for composer.phar in git root folder [HttpKernel][DataCollectorInterface] Ease compatibility Add tests to ensure defaultLocale is properly passed to the URL generator [DependencyInjection] Fix broken references in tests [VarDumper] display the method we're in when dumping stack traces [HttpClient] Retry safe requests when then fail before the body arrives [Console] Rename some methods related to redraw frequency Avoid using of kernel after shutdown Simplify PHP CS Fixer configuration [PropertyInfo] Fixed type extraction for nullable collections of non-nullable elements [FrameworkBundle] [HttpKernel] fixed correct EOL and EOM month Fix CS [Serializer] Fix property name usage for denormalization Name test accordingly to the tested class Fix MockFileSessionStorageTest::sessionDir being used after it's unset [Security] Fix SwitchUserToken wrongly deauthenticated Supporting Bootstrap 4 custom switches Add new Form WeekType bumped Symfony version to 4.3.7 ...
2 parents c7566de + 71bf18e commit f2cd3f0

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

Caster/ExceptionCaster.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, boo
206206
$f['file'] = substr($f['file'], 0, -\strlen($match[0]));
207207
$f['line'] = (int) $match[1];
208208
}
209-
$caller = isset($f['function']) ? sprintf('in %s() on line %d', (isset($f['class']) ? $f['class'].$f['type'] : '').$f['function'], $f['line']) : null;
210209
$src = $f['line'];
211210
$srcKey = $f['file'];
212211
$ellipsis = new LinkStub($srcKey, 0);
@@ -226,13 +225,13 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, boo
226225
$templatePath = null;
227226
}
228227
if ($templateSrc) {
229-
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig', $templatePath);
228+
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, 'twig', $templatePath, $f);
230229
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
231230
}
232231
}
233232
}
234233
if ($srcKey == $f['file']) {
235-
$src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, $caller, 'php', $f['file']);
234+
$src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, 'php', $f['file'], $f);
236235
$srcKey .= ':'.$f['line'];
237236
if ($ellipsis) {
238237
$ellipsis += 1 + \strlen($f['line']);
@@ -308,7 +307,7 @@ private static function traceUnshift(array &$trace, ?string $class, string $file
308307
]);
309308
}
310309

311-
private static function extractSource(string $srcLines, int $line, int $srcContext, ?string $title, string $lang, string $file = null): EnumStub
310+
private static function extractSource(string $srcLines, int $line, int $srcContext, string $lang, ?string $file, array $frame): EnumStub
312311
{
313312
$srcLines = explode("\n", $srcLines);
314313
$src = [];
@@ -317,7 +316,32 @@ private static function extractSource(string $srcLines, int $line, int $srcConte
317316
$src[] = (isset($srcLines[$i]) ? $srcLines[$i] : '')."\n";
318317
}
319318

320-
$srcLines = [];
319+
if ($frame['function'] ?? false) {
320+
$stub = new CutStub(new \stdClass());
321+
$stub->class = (isset($frame['class']) ? $frame['class'].$frame['type'] : '').$frame['function'];
322+
$stub->type = Stub::TYPE_OBJECT;
323+
$stub->attr['cut_hash'] = true;
324+
$stub->attr['file'] = $frame['file'];
325+
$stub->attr['line'] = $frame['line'];
326+
327+
try {
328+
$caller = isset($frame['class']) ? new \ReflectionMethod($frame['class'], $frame['function']) : new \ReflectionFunction($frame['function']);
329+
$stub->class .= ReflectionCaster::getSignature(ReflectionCaster::castFunctionAbstract($caller, [], $stub, true, Caster::EXCLUDE_VERBOSE));
330+
331+
if ($f = $caller->getFileName()) {
332+
$stub->attr['file'] = $f;
333+
$stub->attr['line'] = $caller->getStartLine();
334+
}
335+
} catch (\ReflectionException $e) {
336+
// ignore fake class/function
337+
}
338+
339+
$srcLines = ["\0~separator=\0" => $stub];
340+
} else {
341+
$stub = null;
342+
$srcLines = [];
343+
}
344+
321345
$ltrim = 0;
322346
do {
323347
$pad = null;
@@ -344,7 +368,7 @@ private static function extractSource(string $srcLines, int $line, int $srcConte
344368
if ($i !== $srcContext) {
345369
$c = new ConstStub('default', $c);
346370
} else {
347-
$c = new ConstStub($c, $title);
371+
$c = new ConstStub($c, $stub ? 'in '.$stub->class : '');
348372
if (null !== $file) {
349373
$c->attr['file'] = $file;
350374
$c->attr['line'] = $line;

Dumper/CliDumper.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild)
279279

280280
$class = $this->utf8Encode($class);
281281
if (Cursor::HASH_OBJECT === $type) {
282-
$prefix = $class && 'stdClass' !== $class ? $this->style('note', $class, $attr).' {' : '{';
282+
$prefix = $class && 'stdClass' !== $class ? $this->style('note', $class, $attr).(empty($attr['cut_hash']) ? ' {' : '') : '{';
283283
} elseif (Cursor::HASH_RESOURCE === $type) {
284284
$prefix = $this->style('note', $class.' resource', $attr).($hasChild ? ' {' : ' ');
285285
} else {
286286
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class, $attr).' [' : '[';
287287
}
288288

289-
if ($cursor->softRefCount || 0 < $cursor->softRefHandle) {
289+
if (($cursor->softRefCount || 0 < $cursor->softRefHandle) && empty($attr['cut_hash'])) {
290290
$prefix .= $this->style('ref', (Cursor::HASH_RESOURCE === $type ? '@' : '#').(0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->softRefTo), ['count' => $cursor->softRefCount]);
291291
} elseif ($cursor->hardRefTo && !$cursor->refIndex && $class) {
292292
$prefix .= $this->style('ref', '&'.$cursor->hardRefTo, ['count' => $cursor->hardRefCount]);
@@ -306,8 +306,11 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild)
306306
*/
307307
public function leaveHash(Cursor $cursor, int $type, $class, bool $hasChild, int $cut)
308308
{
309-
$this->dumpEllipsis($cursor, $hasChild, $cut);
310-
$this->line .= Cursor::HASH_OBJECT === $type ? '}' : (Cursor::HASH_RESOURCE !== $type ? ']' : ($hasChild ? '}' : ''));
309+
if (empty($cursor->attr['cut_hash'])) {
310+
$this->dumpEllipsis($cursor, $hasChild, $cut);
311+
$this->line .= Cursor::HASH_OBJECT === $type ? '}' : (Cursor::HASH_RESOURCE !== $type ? ']' : ($hasChild ? '}' : ''));
312+
}
313+
311314
$this->endValue($cursor);
312315
}
313316

Tests/Caster/ExceptionCasterTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function testDefaultSettings()
4747
#line: 28
4848
trace: {
4949
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
50+
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
5051
› {
5152
› return new \Exception(''.$msg);
5253
› }
@@ -66,11 +67,12 @@ public function testSeek()
6667
$expectedDump = <<<'EODUMP'
6768
{
6869
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
70+
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
6971
› {
7072
› return new \Exception(''.$msg);
7173
› }
7274
}
73-
%s%eTests%eCaster%eExceptionCasterTest.php:64 { …}
75+
%s%eTests%eCaster%eExceptionCasterTest.php:65 { …}
7476
%A
7577
EODUMP;
7678

@@ -90,11 +92,12 @@ public function testNoArgs()
9092
#line: 28
9193
trace: {
9294
%sExceptionCasterTest.php:28 {
95+
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
9396
› {
9497
› return new \Exception(''.$msg);
9598
› }
9699
}
97-
%s%eTests%eCaster%eExceptionCasterTest.php:82 { …}
100+
%s%eTests%eCaster%eExceptionCasterTest.php:84 { …}
98101
%A
99102
EODUMP;
100103

Tests/Dumper/CliDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function testDumpWithCommaFlagsAndExceptionCodeExcerpt()
143143
#line: %d
144144
trace: {
145145
%ACliDumperTest.php:%d {
146+
Symfony\Component\VarDumper\Tests\Dumper\CliDumperTest->testDumpWithCommaFlagsAndExceptionCodeExcerpt()
146147
147148
› $ex = new \RuntimeException('foo');
148149
@@ -354,6 +355,7 @@ public function testThrowingCaster()
354355
#message: "Unexpected Exception thrown from a caster: Foobar"
355356
trace: {
356357
%sTwig.php:2 {
358+
__TwigTemplate_VarDumperFixture_u75a09->doDisplay(array \$context, array \$blocks = [])
357359
› foo bar
358360
› twig source
359361

0 commit comments

Comments
 (0)