Symfony\Component\VarDumper\Caster\ExceptionCaster::castFrameStub PHP Method

castFrameStub() public static method

public static castFrameStub ( Symfony\Component\VarDumper\Caster\FrameStub $frame, array $a, Symfony\Component\VarDumper\Cloner\Stub $stub, $isNested )
$frame Symfony\Component\VarDumper\Caster\FrameStub
$a array
$stub Symfony\Component\VarDumper\Cloner\Stub
    public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $isNested)
    {
        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];
                }
                $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'];
                $srcKey = $f['file'];
                $ellipsis = explode(DIRECTORY_SEPARATOR, $srcKey);
                $ellipsis = 3 < count($ellipsis) ? 2 + strlen(implode(array_slice($ellipsis, -2))) : 0;
                if (file_exists($f['file']) && 0 <= self::$srcContext) {
                    if (!empty($f['class']) && is_subclass_of($f['class'], 'Twig_Template') && method_exists($f['class'], 'getDebugInfo')) {
                        $template = isset($f['object']) ? $f['object'] : unserialize(sprintf('O:%d:"%s":0:{}', strlen($f['class']), $f['class']));
                        $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') || !file_exists($templatePath = $template->getSourceContext()->getPath())) {
                                $templatePath = null;
                            }
                            if ($templateSrc) {
                                $src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig', $templatePath);
                                $srcKey = ($templatePath ?: $template->getTemplateName()) . ':' . $templateInfo[$f['line']];
                            }
                        }
                    }
                    if ($srcKey == $f['file']) {
                        $src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, $caller, 'php', $f['file']);
                        $srcKey .= ':' . $f['line'];
                        if ($ellipsis) {
                            $ellipsis += 1 + strlen($f['line']);
                        }
                    }
                }
                $srcAttr = $ellipsis ? 'ellipsis=' . $ellipsis : '';
                self::$framesCache[$cacheKey] = $a[$prefix . 'src'] = new EnumStub(array("~{$srcAttr}{$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;
    }

Usage Example

Ejemplo n.º 1
0
 public static function castReflectionGenerator(\ReflectionGenerator $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     if ($c->getThis()) {
         $a[$prefix . 'this'] = new CutStub($c->getThis());
     }
     $x = $c->getFunction();
     $frame = array('class' => isset($x->class) ? $x->class : null, 'type' => isset($x->class) ? $x->isStatic() ? '::' : '->' : null, 'function' => $x->name, 'file' => $c->getExecutingFile(), 'line' => $c->getExecutingLine());
     if ($trace = $c->getTrace(DEBUG_BACKTRACE_IGNORE_ARGS)) {
         $x = new \ReflectionGenerator($c->getExecutingGenerator());
         array_unshift($trace, array('function' => 'yield', 'file' => $x->getExecutingFile(), 'line' => $x->getExecutingLine() - 1));
         $trace[] = $frame;
         $a[$prefix . 'trace'] = new TraceStub($trace, false, 0, -1, -1);
     } else {
         $x = new FrameStub($frame, false, true);
         $x = ExceptionCaster::castFrameStub($x, array(), $x, true);
         $a[$prefix . 'executing'] = new EnumStub(array($frame['class'] . $frame['type'] . $frame['function'] . '()' => $x[$prefix . 'src']));
     }
     return $a;
 }