You are here

public function DumpDataCollector::dump in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/DataCollector/DumpDataCollector.php \Symfony\Component\HttpKernel\DataCollector\DumpDataCollector::dump()

File

vendor/symfony/http-kernel/DataCollector/DumpDataCollector.php, line 64

Class

DumpDataCollector
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\HttpKernel\DataCollector

Code

public function dump(Data $data) {
  if ($this->stopwatch) {
    $this->stopwatch
      ->start('dump');
  }
  if ($this->isCollected) {
    $this->isCollected = false;
  }
  $trace = DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS;
  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 = method_exists($info, 'getSource') ? $info
            ->getSource() : $info
            ->getEnvironment()
            ->getLoader()
            ->getSource($name);
          $info = $info
            ->getDebugInfo();
          if (null !== $src && 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 = str_replace('\\', '/', $file);
    $name = substr($name, strrpos($name, '/') + 1);
  }
  if ($this->dumper) {
    $this
      ->doDump($data, $name, $file, $line);
  }
  $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
  ++$this->dataCount;
  if ($this->stopwatch) {
    $this->stopwatch
      ->stop('dump');
  }
}