Symfony\Component\HttpKernel\DataCollector\DumpDataCollector::dump PHP Method

dump() public method

public dump ( Symfony\Component\VarDumper\Cloner\Data $data )
$data Symfony\Component\VarDumper\Cloner\Data
    public function dump(Data $data)
    {
        if ($this->stopwatch) {
            $this->stopwatch->start('dump');
        }
        if ($this->isCollected) {
            $this->isCollected = false;
        }
        $trace = PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS : true;
        if (PHP_VERSION_ID >= 50400) {
            $trace = debug_backtrace($trace, 7);
        } else {
            $trace = debug_backtrace($trace);
        }
        $file = $trace[0]['file'];
        $line = $trace[0]['line'];
        $name = false;
        $fileExcerpt = false;
        for ($i = 1; $i < 7; ++$i) {
            if (isset($trace[$i]['class'], $trace[$i]['function']) && 'dump' === $trace[$i]['function'] && 'Symfony\\Component\\VarDumper\\VarDumper' === $trace[$i]['class']) {
                $file = $trace[$i]['file'];
                $line = $trace[$i]['line'];
                while (++$i < 7) {
                    if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && 0 !== strpos($trace[$i]['function'], 'call_user_func')) {
                        $file = $trace[$i]['file'];
                        $line = $trace[$i]['line'];
                        break;
                    } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) {
                        $info = $trace[$i]['object'];
                        $name = $info->getTemplateName();
                        $src = $info->getEnvironment()->getLoader()->getSource($name);
                        $info = $info->getDebugInfo();
                        if (isset($info[$trace[$i - 1]['line']])) {
                            $file = false;
                            $line = $info[$trace[$i - 1]['line']];
                            $src = explode("\n", $src);
                            $fileExcerpt = array();
                            for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
                                $fileExcerpt[] = '<li' . ($i === $line ? ' class="selected"' : '') . '><code>' . $this->htmlEncode($src[$i - 1]) . '</code></li>';
                            }
                            $fileExcerpt = '<ol start="' . max($line - 3, 1) . '">' . implode("\n", $fileExcerpt) . '</ol>';
                        }
                        break;
                    }
                }
                break;
            }
        }
        if (false === $name) {
            $name = strtr($file, '\\', '/');
            $name = substr($name, strrpos($name, '/') + 1);
        }
        $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
        ++$this->dataCount;
        if ($this->stopwatch) {
            $this->stopwatch->stop('dump');
        }
    }

Usage Example

Esempio n. 1
0
 public function testFlush()
 {
     $data = new Data(array(array(456)));
     $collector = new DumpDataCollector();
     $collector->dump($data);
     $line = __LINE__;
     ob_start();
     $collector = null;
     $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
 }
All Usage Examples Of Symfony\Component\HttpKernel\DataCollector\DumpDataCollector::dump