[VarDumper] display the method we're in when dumping stack traces
This commit is contained in:
parent
8e2bc5fe0a
commit
23600cc8e1
@ -206,7 +206,6 @@ class ExceptionCaster
|
|||||||
$f['file'] = substr($f['file'], 0, -\strlen($match[0]));
|
$f['file'] = substr($f['file'], 0, -\strlen($match[0]));
|
||||||
$f['line'] = (int) $match[1];
|
$f['line'] = (int) $match[1];
|
||||||
}
|
}
|
||||||
$caller = isset($f['function']) ? sprintf('in %s() on line %d', (isset($f['class']) ? $f['class'].$f['type'] : '').$f['function'], $f['line']) : null;
|
|
||||||
$src = $f['line'];
|
$src = $f['line'];
|
||||||
$srcKey = $f['file'];
|
$srcKey = $f['file'];
|
||||||
$ellipsis = new LinkStub($srcKey, 0);
|
$ellipsis = new LinkStub($srcKey, 0);
|
||||||
@ -226,13 +225,13 @@ class ExceptionCaster
|
|||||||
$templatePath = null;
|
$templatePath = null;
|
||||||
}
|
}
|
||||||
if ($templateSrc) {
|
if ($templateSrc) {
|
||||||
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig', $templatePath);
|
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, 'twig', $templatePath, $f);
|
||||||
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
|
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($srcKey == $f['file']) {
|
if ($srcKey == $f['file']) {
|
||||||
$src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, $caller, 'php', $f['file']);
|
$src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, 'php', $f['file'], $f);
|
||||||
$srcKey .= ':'.$f['line'];
|
$srcKey .= ':'.$f['line'];
|
||||||
if ($ellipsis) {
|
if ($ellipsis) {
|
||||||
$ellipsis += 1 + \strlen($f['line']);
|
$ellipsis += 1 + \strlen($f['line']);
|
||||||
@ -308,7 +307,7 @@ class ExceptionCaster
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function extractSource(string $srcLines, int $line, int $srcContext, ?string $title, string $lang, string $file = null): EnumStub
|
private static function extractSource(string $srcLines, int $line, int $srcContext, string $lang, ?string $file, array $frame): EnumStub
|
||||||
{
|
{
|
||||||
$srcLines = explode("\n", $srcLines);
|
$srcLines = explode("\n", $srcLines);
|
||||||
$src = [];
|
$src = [];
|
||||||
@ -317,7 +316,32 @@ class ExceptionCaster
|
|||||||
$src[] = (isset($srcLines[$i]) ? $srcLines[$i] : '')."\n";
|
$src[] = (isset($srcLines[$i]) ? $srcLines[$i] : '')."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($frame['function'] ?? false) {
|
||||||
|
$stub = new CutStub(new \stdClass());
|
||||||
|
$stub->class = (isset($frame['class']) ? $frame['class'].$frame['type'] : '').$frame['function'];
|
||||||
|
$stub->type = Stub::TYPE_OBJECT;
|
||||||
|
$stub->attr['cut_hash'] = true;
|
||||||
|
$stub->attr['file'] = $frame['file'];
|
||||||
|
$stub->attr['line'] = $frame['line'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$caller = isset($frame['class']) ? new \ReflectionMethod($frame['class'], $frame['function']) : new \ReflectionFunction($frame['function']);
|
||||||
|
$stub->class .= ReflectionCaster::getSignature(ReflectionCaster::castFunctionAbstract($caller, [], $stub, true, Caster::EXCLUDE_VERBOSE));
|
||||||
|
|
||||||
|
if ($f = $caller->getFileName()) {
|
||||||
|
$stub->attr['file'] = $f;
|
||||||
|
$stub->attr['line'] = $caller->getStartLine();
|
||||||
|
}
|
||||||
|
} catch (\ReflectionException $e) {
|
||||||
|
// ignore fake class/function
|
||||||
|
}
|
||||||
|
|
||||||
|
$srcLines = ["\0~separator=\0" => $stub];
|
||||||
|
} else {
|
||||||
|
$stub = null;
|
||||||
$srcLines = [];
|
$srcLines = [];
|
||||||
|
}
|
||||||
|
|
||||||
$ltrim = 0;
|
$ltrim = 0;
|
||||||
do {
|
do {
|
||||||
$pad = null;
|
$pad = null;
|
||||||
@ -344,7 +368,7 @@ class ExceptionCaster
|
|||||||
if ($i !== $srcContext) {
|
if ($i !== $srcContext) {
|
||||||
$c = new ConstStub('default', $c);
|
$c = new ConstStub('default', $c);
|
||||||
} else {
|
} else {
|
||||||
$c = new ConstStub($c, $title);
|
$c = new ConstStub($c, $stub ? 'in '.$stub->class : '');
|
||||||
if (null !== $file) {
|
if (null !== $file) {
|
||||||
$c->attr['file'] = $file;
|
$c->attr['file'] = $file;
|
||||||
$c->attr['line'] = $line;
|
$c->attr['line'] = $line;
|
||||||
|
@ -283,14 +283,14 @@ class CliDumper extends AbstractDumper
|
|||||||
|
|
||||||
$class = $this->utf8Encode($class);
|
$class = $this->utf8Encode($class);
|
||||||
if (Cursor::HASH_OBJECT === $type) {
|
if (Cursor::HASH_OBJECT === $type) {
|
||||||
$prefix = $class && 'stdClass' !== $class ? $this->style('note', $class, $attr).' {' : '{';
|
$prefix = $class && 'stdClass' !== $class ? $this->style('note', $class, $attr).(empty($attr['cut_hash']) ? ' {' : '') : '{';
|
||||||
} elseif (Cursor::HASH_RESOURCE === $type) {
|
} elseif (Cursor::HASH_RESOURCE === $type) {
|
||||||
$prefix = $this->style('note', $class.' resource', $attr).($hasChild ? ' {' : ' ');
|
$prefix = $this->style('note', $class.' resource', $attr).($hasChild ? ' {' : ' ');
|
||||||
} else {
|
} else {
|
||||||
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class, $attr).' [' : '[';
|
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class, $attr).' [' : '[';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cursor->softRefCount || 0 < $cursor->softRefHandle) {
|
if (($cursor->softRefCount || 0 < $cursor->softRefHandle) && empty($attr['cut_hash'])) {
|
||||||
$prefix .= $this->style('ref', (Cursor::HASH_RESOURCE === $type ? '@' : '#').(0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->softRefTo), ['count' => $cursor->softRefCount]);
|
$prefix .= $this->style('ref', (Cursor::HASH_RESOURCE === $type ? '@' : '#').(0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->softRefTo), ['count' => $cursor->softRefCount]);
|
||||||
} elseif ($cursor->hardRefTo && !$cursor->refIndex && $class) {
|
} elseif ($cursor->hardRefTo && !$cursor->refIndex && $class) {
|
||||||
$prefix .= $this->style('ref', '&'.$cursor->hardRefTo, ['count' => $cursor->hardRefCount]);
|
$prefix .= $this->style('ref', '&'.$cursor->hardRefTo, ['count' => $cursor->hardRefCount]);
|
||||||
@ -310,8 +310,11 @@ class CliDumper extends AbstractDumper
|
|||||||
*/
|
*/
|
||||||
public function leaveHash(Cursor $cursor, $type, $class, $hasChild, $cut)
|
public function leaveHash(Cursor $cursor, $type, $class, $hasChild, $cut)
|
||||||
{
|
{
|
||||||
|
if (empty($cursor->attr['cut_hash'])) {
|
||||||
$this->dumpEllipsis($cursor, $hasChild, $cut);
|
$this->dumpEllipsis($cursor, $hasChild, $cut);
|
||||||
$this->line .= Cursor::HASH_OBJECT === $type ? '}' : (Cursor::HASH_RESOURCE !== $type ? ']' : ($hasChild ? '}' : ''));
|
$this->line .= Cursor::HASH_OBJECT === $type ? '}' : (Cursor::HASH_RESOURCE !== $type ? ']' : ($hasChild ? '}' : ''));
|
||||||
|
}
|
||||||
|
|
||||||
$this->endValue($cursor);
|
$this->endValue($cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ Exception {
|
|||||||
#line: 28
|
#line: 28
|
||||||
trace: {
|
trace: {
|
||||||
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
|
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
|
||||||
|
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
|
||||||
› {
|
› {
|
||||||
› return new \Exception(''.$msg);
|
› return new \Exception(''.$msg);
|
||||||
› }
|
› }
|
||||||
@ -66,11 +67,12 @@ EODUMP;
|
|||||||
$expectedDump = <<<'EODUMP'
|
$expectedDump = <<<'EODUMP'
|
||||||
{
|
{
|
||||||
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
|
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
|
||||||
|
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
|
||||||
› {
|
› {
|
||||||
› return new \Exception(''.$msg);
|
› return new \Exception(''.$msg);
|
||||||
› }
|
› }
|
||||||
}
|
}
|
||||||
%s%eTests%eCaster%eExceptionCasterTest.php:64 { …}
|
%s%eTests%eCaster%eExceptionCasterTest.php:65 { …}
|
||||||
%A
|
%A
|
||||||
EODUMP;
|
EODUMP;
|
||||||
|
|
||||||
@ -90,11 +92,12 @@ Exception {
|
|||||||
#line: 28
|
#line: 28
|
||||||
trace: {
|
trace: {
|
||||||
%sExceptionCasterTest.php:28 {
|
%sExceptionCasterTest.php:28 {
|
||||||
|
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
|
||||||
› {
|
› {
|
||||||
› return new \Exception(''.$msg);
|
› return new \Exception(''.$msg);
|
||||||
› }
|
› }
|
||||||
}
|
}
|
||||||
%s%eTests%eCaster%eExceptionCasterTest.php:82 { …}
|
%s%eTests%eCaster%eExceptionCasterTest.php:84 { …}
|
||||||
%A
|
%A
|
||||||
EODUMP;
|
EODUMP;
|
||||||
|
|
||||||
|
@ -143,6 +143,7 @@ RuntimeException {
|
|||||||
#line: %d
|
#line: %d
|
||||||
trace: {
|
trace: {
|
||||||
%ACliDumperTest.php:%d {
|
%ACliDumperTest.php:%d {
|
||||||
|
Symfony\Component\VarDumper\Tests\Dumper\CliDumperTest->testDumpWithCommaFlagsAndExceptionCodeExcerpt()
|
||||||
›
|
›
|
||||||
› $ex = new \RuntimeException('foo');
|
› $ex = new \RuntimeException('foo');
|
||||||
›
|
›
|
||||||
@ -382,6 +383,7 @@ stream resource {@{$ref}
|
|||||||
#message: "Unexpected Exception thrown from a caster: Foobar"
|
#message: "Unexpected Exception thrown from a caster: Foobar"
|
||||||
trace: {
|
trace: {
|
||||||
%sTwig.php:2 {
|
%sTwig.php:2 {
|
||||||
|
__TwigTemplate_VarDumperFixture_u75a09->doDisplay(array \$context, array \$blocks = [])
|
||||||
› foo bar
|
› foo bar
|
||||||
› twig source
|
› twig source
|
||||||
›
|
›
|
||||||
|
Reference in New Issue
Block a user