Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExceptionCaster.php

function ExceptionCaster::castTraceStub

File

vendor/symfony/var-dumper/Caster/ExceptionCaster.php, line 114

Class

ExceptionCaster
Casts common Exception classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, bool $isNested) : array {
    if (!$isNested) {
        return $a;
    }
    $stub->class = '';
    $stub->handle = 0;
    $frames = $trace->value;
    $prefix = Caster::PREFIX_VIRTUAL;
    $a = [];
    $j = \count($frames);
    if (0 > ($i = $trace->sliceOffset)) {
        $i = max(0, $j + $i);
    }
    if (!isset($trace->value[$i])) {
        return [];
    }
    $lastCall = isset($frames[$i]['function']) ? (isset($frames[$i]['class']) ? $frames[0]['class'] . $frames[$i]['type'] : '') . $frames[$i]['function'] . '()' : '';
    $frames[] = [
        'function' => '',
    ];
    $collapse = false;
    for ($j += $trace->numberingOffset - $i++; isset($frames[$i]); ++$i, --$j) {
        $f = $frames[$i];
        $call = isset($f['function']) ? (isset($f['class']) ? $f['class'] . $f['type'] : '') . $f['function'] : '???';
        $frame = new FrameStub([
            'object' => $f['object'] ?? null,
            'class' => $f['class'] ?? null,
            'type' => $f['type'] ?? null,
            'function' => $f['function'] ?? null,
        ] + $frames[$i - 1], false, true);
        $f = self::castFrameStub($frame, [], $frame, true);
        if (isset($f[$prefix . 'src'])) {
            foreach ($f[$prefix . 'src']->value as $label => $frame) {
                if (str_starts_with($label, "\x00~collapse=0")) {
                    if ($collapse) {
                        $label = substr_replace($label, '1', 11, 1);
                    }
                    else {
                        $collapse = true;
                    }
                }
                $label = substr_replace($label, "title=Stack level {$j}.&", 2, 0);
            }
            $f = $frames[$i - 1];
            if ($trace->keepArgs && !empty($f['args']) && $frame instanceof EnumStub) {
                $frame->value['arguments'] = new ArgsStub($f['args'], $f['function'] ?? null, $f['class'] ?? null);
            }
        }
        elseif ('???' !== $lastCall) {
            $label = new ClassStub($lastCall);
            if (isset($label->attr['ellipsis'])) {
                $label->attr['ellipsis'] += 2;
                $label = substr_replace($prefix, "ellipsis-type=class&ellipsis={$label->attr['ellipsis']}&ellipsis-tail=1&title=Stack level {$j}.", 2, 0) . $label->value . '()';
            }
            else {
                $label = substr_replace($prefix, "title=Stack level {$j}.", 2, 0) . $label->value . '()';
            }
        }
        else {
            $label = substr_replace($prefix, "title=Stack level {$j}.", 2, 0) . $lastCall;
        }
        $a[substr_replace($label, \sprintf('separator=%s&', $frame instanceof EnumStub ? ' ' : ':'), 2, 0)] = $frame;
        $lastCall = $call;
    }
    if (null !== $trace->sliceLength) {
        $a = \array_slice($a, 0, $trace->sliceLength, true);
    }
    return $a;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal