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

Breadcrumb

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

function ExceptionCaster::castFrameStub

2 calls to ExceptionCaster::castFrameStub()
ExceptionCaster::castTraceStub in vendor/symfony/var-dumper/Caster/ExceptionCaster.php
ReflectionCaster::castReflectionGenerator in vendor/symfony/var-dumper/Caster/ReflectionCaster.php

File

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

Class

ExceptionCaster
Casts common Exception classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, bool $isNested) : array {
    if (!$isNested) {
        return $a;
    }
    $f = $frame->value;
    $prefix = Caster::PREFIX_VIRTUAL;
    if (isset($f['file'], $f['line'])) {
        $cacheKey = $f;
        unset($cacheKey['object'], $cacheKey['args']);
        $cacheKey[] = self::$srcContext;
        $cacheKey = implode('-', $cacheKey);
        if (isset(self::$framesCache[$cacheKey])) {
            $a[$prefix . 'src'] = self::$framesCache[$cacheKey];
        }
        else {
            if (preg_match('/\\((\\d+)\\)(?:\\([\\da-f]{32}\\))? : (?:eval\\(\\)\'d code|runtime-created function)$/', $f['file'], $match)) {
                $f['file'] = substr($f['file'], 0, -\strlen($match[0]));
                $f['line'] = (int) $match[1];
            }
            $src = $f['line'];
            $srcKey = $f['file'];
            $ellipsis = new LinkStub($srcKey, 0);
            $srcAttr = 'collapse=' . (int) $ellipsis->inVendor;
            $ellipsisTail = $ellipsis->attr['ellipsis-tail'] ?? 0;
            $ellipsis = $ellipsis->attr['ellipsis'] ?? 0;
            if (is_file($f['file']) && 0 <= self::$srcContext) {
                if (!empty($f['class']) && is_subclass_of($f['class'], 'Twig\\Template')) {
                    $template = null;
                    if (isset($f['object'])) {
                        $template = $f['object'];
                    }
                    elseif ((new \ReflectionClass($f['class']))->isInstantiable()) {
                        $template = unserialize(\sprintf('O:%d:"%s":0:{}', \strlen($f['class']), $f['class']));
                    }
                    if (null !== $template) {
                        $ellipsis = 0;
                        $templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()
                            ->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
                        $templateInfo = $template->getDebugInfo();
                        if (isset($templateInfo[$f['line']])) {
                            if (!method_exists($template, 'getSourceContext') || !is_file($templatePath = $template->getSourceContext()
                                ->getPath())) {
                                $templatePath = null;
                            }
                            if ($templateSrc) {
                                $src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, 'twig', $templatePath, $f);
                                $srcKey = ($templatePath ?: $template->getTemplateName()) . ':' . $templateInfo[$f['line']];
                            }
                        }
                    }
                }
                if ($srcKey == $f['file']) {
                    $src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, 'php', $f['file'], $f);
                    $srcKey .= ':' . $f['line'];
                    if ($ellipsis) {
                        $ellipsis += 1 + \strlen($f['line']);
                    }
                }
                $srcAttr .= \sprintf('&separator= &file=%s&line=%d', rawurlencode($f['file']), $f['line']);
            }
            else {
                $srcAttr .= '&separator=:';
            }
            $srcAttr .= $ellipsis ? '&ellipsis-type=path&ellipsis=' . $ellipsis . '&ellipsis-tail=' . $ellipsisTail : '';
            self::$framesCache[$cacheKey] = $a[$prefix . 'src'] = new EnumStub([
                "\x00~{$srcAttr}\x00{$srcKey}" => $src,
            ]);
        }
    }
    unset($a[$prefix . 'args'], $a[$prefix . 'line'], $a[$prefix . 'file']);
    if ($frame->inTraceStub) {
        unset($a[$prefix . 'class'], $a[$prefix . 'type'], $a[$prefix . 'function']);
    }
    foreach ($a as $k => $v) {
        if (!$v) {
            unset($a[$k]);
        }
    }
    if ($frame->keepArgs && !empty($f['args'])) {
        $a[$prefix . 'arguments'] = new ArgsStub($f['args'], $f['function'], $f['class']);
    }
    return $a;
}
RSS feed
Powered by Drupal