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

Breadcrumb

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

function ExceptionCaster::extractSource

1 call to ExceptionCaster::extractSource()
ExceptionCaster::castFrameStub in vendor/symfony/var-dumper/Caster/ExceptionCaster.php

File

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

Class

ExceptionCaster
Casts common Exception classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

private static function extractSource(string $srcLines, int $line, int $srcContext, string $lang, ?string $file, array $frame) : EnumStub {
    $srcLines = explode("\n", $srcLines);
    $src = [];
    for ($i = $line - 1 - $srcContext; $i <= $line - 1 + $srcContext; ++$i) {
        $src[] = ($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) {
            // ignore fake class/function
        }
        $srcLines = [
            "\x00~separator=\x00" => $stub,
        ];
    }
    else {
        $stub = null;
        $srcLines = [];
    }
    $ltrim = 0;
    do {
        $pad = null;
        for ($i = $srcContext << 1; $i >= 0; --$i) {
            if (isset($src[$i][$ltrim]) && "\r" !== ($c = $src[$i][$ltrim]) && "\n" !== $c) {
                $pad ??= $c;
                if (' ' !== $c && "\t" !== $c || $pad !== $c) {
                    break;
                }
            }
        }
        ++$ltrim;
    } while (0 > $i && null !== $pad);
    --$ltrim;
    foreach ($src as $i => $c) {
        if ($ltrim) {
            $c = isset($c[$ltrim]) && "\r" !== $c[$ltrim] ? substr($c, $ltrim) : ltrim($c, " \t");
        }
        $c = substr($c, 0, -1);
        if ($i !== $srcContext) {
            $c = new ConstStub('default', $c);
        }
        else {
            $c = new ConstStub($c, $stub ? 'in ' . $stub->class : '');
            if (null !== $file) {
                $c->attr['file'] = $file;
                $c->attr['line'] = $line;
            }
        }
        $c->attr['lang'] = $lang;
        $srcLines[\sprintf("\x00~separator=› &%d\x00", $i + $line - $srcContext)] = $c;
    }
    return new EnumStub($srcLines);
}

API Navigation

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