* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\DataCollector; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Symfony\Component\VarDumper\Dumper\DataDumperInterface; use Twig\Template; /** * @author Nicolas Grekas */ class DumpDataCollector extends DataCollector implements DataDumperInterface { private $stopwatch; private $fileLinkFormat; private $dataCount = 0; private $isCollected = true; private $clonesCount = 0; private $clonesIndex = 0; private $rootRefs; private $charset; private $requestStack; private $dumper; private $dumperIsInjected; public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null) { $this->stopwatch = $stopwatch; $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); $this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8'; $this->requestStack = $requestStack; $this->dumper = $dumper; $this->dumperIsInjected = null !== $dumper; // All clones share these properties by reference: $this->rootRefs = array( &$this->data, &$this->dataCount, &$this->isCollected, &$this->clonesCount, ); } public function __clone() { $this->clonesIndex = ++$this->clonesCount; } public function dump(Data $data) { if ($this->stopwatch) { $this->stopwatch->start('dump'); } if ($this->isCollected && !$this->dumper) { $this->isCollected = false; } $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 7); $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 Template) { $template = $trace[$i]['object']; $name = $template->getTemplateName(); $src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false); $info = $template->getDebugInfo(); if (isset($info[$trace[$i - 1]['line']])) { $line = $info[$trace[$i - 1]['line']]; $file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null; if ($src) { $src = explode("\n", $src); $fileExcerpt = array(); for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) { $fileExcerpt[] = ''.$this->htmlEncode($src[$i - 1]).''; } $fileExcerpt = '
    '.implode("\n", $fileExcerpt).'
'; } } 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'); } } public function collect(Request $request, Response $response, \Exception $exception = null) { // Sub-requests and programmatic calls stay in the collected profile. if ($this->dumper || ($this->requestStack && $this->requestStack->getMasterRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) { return; } // In all other conditions that remove the web debug toolbar, dumps are written on the output. if (!$this->requestStack || !$response->headers->has('X-Debug-Token') || $response->isRedirection() || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) || 'html' !== $request->getRequestFormat() || false === strripos($response->getContent(), '') ) { if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) { $this->dumper = new HtmlDumper('php://output', $this->charset); $this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); } else { $this->dumper = new CliDumper('php://output', $this->charset); } foreach ($this->data as $dump) { $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']); } } } public function reset() { if ($this->stopwatch) { $this->stopwatch->reset(); } $this->data = array(); $this->dataCount = 0; $this->isCollected = false; $this->clonesCount = 0; $this->clonesIndex = 0; } public function serialize() { if ($this->clonesCount !== $this->clonesIndex) { return 'a:0:{}'; } $this->data[] = $this->fileLinkFormat; $this->data[] = $this->charset; $ser = serialize($this->data); $this->data = array(); $this->dataCount = 0; $this->isCollected = true; if (!$this->dumperIsInjected) { $this->dumper = null; } return $ser; } public function unserialize($data) { parent::unserialize($data); $charset = array_pop($this->data); $fileLinkFormat = array_pop($this->data); $this->dataCount = count($this->data); self::__construct($this->stopwatch, $fileLinkFormat, $charset); } public function getDumpsCount() { return $this->dataCount; } public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1) { $data = fopen('php://memory', 'r+b'); if ('html' === $format) { $dumper = new HtmlDumper($data, $this->charset); $dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); } else { throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format)); } $dumps = array(); foreach ($this->data as $dump) { $dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth)); $dump['data'] = stream_get_contents($data, -1, 0); ftruncate($data, 0); rewind($data); $dumps[] = $dump; } return $dumps; } public function getName() { return 'dump'; } public function __destruct() { if (0 === $this->clonesCount-- && !$this->isCollected && $this->data) { $this->clonesCount = 0; $this->isCollected = true; $h = headers_list(); $i = count($h); array_unshift($h, 'Content-Type: '.ini_get('default_mimetype')); while (0 !== stripos($h[$i], 'Content-Type:')) { --$i; } if (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true) && stripos($h[$i], 'html')) { $this->dumper = new HtmlDumper('php://output', $this->charset); $this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); } else { $this->dumper = new CliDumper('php://output', $this->charset); } foreach ($this->data as $i => $dump) { $this->data[$i] = null; $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']); } $this->data = array(); $this->dataCount = 0; } } private function doDump($data, $name, $file, $line) { if ($this->dumper instanceof CliDumper) { $contextDumper = function ($name, $file, $line, $fmt) { if ($this instanceof HtmlDumper) { if ($file) { $s = $this->style('meta', '%s'); $f = strip_tags($this->style('', $file)); $name = strip_tags($this->style('', $name)); if ($fmt && $link = is_string($fmt) ? strtr($fmt, array('%f' => $file, '%l' => $line)) : $fmt->format($file, $line)) { $name = sprintf(''.$s.'', strip_tags($this->style('', $link)), $f, $name); } else { $name = sprintf(''.$s.'', $f, $name); } } else { $name = $this->style('meta', $name); } $this->line = $name.' on line '.$this->style('meta', $line).':'; } else { $this->line = $this->style('meta', $name).' on line '.$this->style('meta', $line).':'; } $this->dumpLine(0); }; $contextDumper = $contextDumper->bindTo($this->dumper, $this->dumper); $contextDumper($name, $file, $line, $this->fileLinkFormat); } else { $cloner = new VarCloner(); $this->dumper->dump($cloner->cloneVar($name.' on line '.$line.':')); } $this->dumper->dump($data); } private function htmlEncode($s) { $html = ''; $dumper = new HtmlDumper(function ($line) use (&$html) { $html .= $line; }, $this->charset); $dumper->setDumpHeader(''); $dumper->setDumpBoundaries('', ''); $cloner = new VarCloner(); $dumper->dump($cloner->cloneVar($s)); return substr(strip_tags($html), 1, -1); } } __halt_compiler();----SIGNATURE:----VB2qj1aq/aNkNmdYviJHtCcmR/RTUVIpH+CaaLzdzGm6TBArL2ocxXqFbafT3RuPFs1ZXEreGoqv5DR1LW0k1e+hOTOp6XJO72gI+zR+q45/bPa9AdrM/nJReb1HOt5+/kZh82U27XBF74Kpt/U2w9LG1yNlnRrr+kF7zWNwYaG5GwU1hvXCefsahdK0HN54bdGbcqXVWxFw9fk4S5VY44ewWW5hMfz6VDYucd++5Desw5ciTMwmYDRNWRq0bQOUVE0XoSR8CNbifGZ3F+wvcxFuFIDUlsIUvQNPkPB4hrXirY+m7/TUct5PuAZhc7KwW8Oci55zijp67myIlBG37bSyFbt4QPxjyunGIPUfN057XIPoMlJ4JoWKZ73zeYi6GwotexqfYShLbmU2spe1r0gkA6xi6iw/yjNwRP+cOiJJIct8TcDoVam4K5NmBMCgfltulzFXNfJYP5AwvLKoQJyyHIUsYF/WOci6yvAJSmZba9+tDEKA9MtDnkE2MyW4Q3AKHzhZIIYZlhXhRalHQ+90R3aw8kHtv9ZrQTY2ruYRdjxzAlqdE+bDi/Bt/avLB33A3qw7AQtQH24hMFsPqlOKVz5p0J0ZGuvYhI0Opecmfksj3+35mP1A70kW52HeReh8krPzsoc6b+b/MpUiDzZoWKQavd483TBnyx0Nw50=----ATTACHMENT:----ODA2MjE0NjI3Nzk0MTQzMSA5NjM4MTQ0NDA4NTk2Mzc0IDI4NTYwNDM5MDg0NTQ0MDk=