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

__destruct() public method

public __destruct ( )
    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 ('cli' !== PHP_SAPI && stripos($h[$i], 'html')) {
                $dumper = new HtmlDumper('php://output', $this->charset);
            } else {
                $dumper = new CliDumper('php://output', $this->charset);
                $dumper->setColors(false);
            }
            foreach ($this->data as $i => $dump) {
                $this->data[$i] = null;
                if ($dumper instanceof HtmlDumper) {
                    $dump['name'] = $this->htmlEncode($dump['name']);
                    $dump['file'] = $this->htmlEncode($dump['file']);
                    if ('' !== $dump['file']) {
                        if ($this->fileLinkFormat) {
                            $link = strtr($this->fileLinkFormat, array('%f' => $dump['file'], '%l' => $dump['line']));
                            $dump['name'] = sprintf('<a href="%s" title="%s">%s</a>', $link, $dump['file'], $dump['name']);
                        } else {
                            $dump['name'] = sprintf('<abbr title="%s">%s</abbr>', $dump['file'], $dump['name']);
                        }
                    }
                    echo "\n<span class=\"sf-dump-meta\">{$dump['name']} on line {$dump['line']}:</span>";
                } else {
                    echo "{$dump['name']} on line {$dump['line']}:\n";
                }
                $dumper->dump($dump['data']);
            }
            $this->data = array();
            $this->dataCount = 0;
        }
    }

Usage Example

コード例 #1
0
 public function testFlush()
 {
     $data = new Data(array(array(456)));
     $collector = new DumpDataCollector();
     $collector->dump($data);
     $line = __LINE__ - 1;
     ob_start();
     $collector->__destruct();
     $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
 }