/** * Dumps information about a variable in readable format. * @param mixed variable to dump * @param bool return output instead of printing it? (bypasses $productionMode) * @return mixed variable itself or dump */ public static function dump($var, $return = FALSE) { if (!$return && self::$productionMode) { return $var; } $output = "<pre class=\"nette-dump\">" . DebugHelpers::htmlDump($var) . "</pre>\n"; if (!$return) { $trace = PHP_VERSION_ID < 50205 ? debug_backtrace() : debug_backtrace(FALSE); $item = ($tmp = DebugHelpers::findTrace($trace, 'dump')) ? $tmp : DebugHelpers::findTrace($trace, __CLASS__ . '::dump'); if (isset($item['file'], $item['line']) && is_file($item['file'])) { $lines = file($item['file']); preg_match('#dump\\((.*)\\)#', $lines[$item['line'] - 1], $m); $output = substr_replace($output, ' title="' . htmlspecialchars((isset($m[0]) ? "{$m['0']} \n" : '') . "in file {$item['file']} on line {$item['line']}") . '"', 4, 0); if (self::$showLocation) { $output = substr_replace($output, ' <small>in ' . DebugHelpers::editorLink($item['file'], $item['line']) . ":{$item['line']}</small>", -8, 0); } } } if (self::$consoleMode) { if (self::$consoleColors && substr(getenv('TERM'), 0, 5) === 'xterm') { $output = preg_replace_callback('#<span class="php-(\\w+)">|</span>#', create_function('$m', ' return "\\033[" . (isset($m[1], Debugger::$consoleColors[$m[1]]) ? Debugger::$consoleColors[$m[1]] : \'0\') . "m"; '), $output); } $output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES); } if ($return) { return $output; } else { echo $output; return $var; } }
public function getPanel() { ob_start(); $data = $this->data; if ($this->id === 'dumps') { ?> <style>#nette-debug .nette-DumpPanel h2{font:11pt/1.5 sans-serif;margin:0;padding:2px 8px;background:#3484d2;color:white}#nette-debug .nette-DumpPanel table{width:100%}#nette-debug .nette-DumpPanel a{color:#333;background:transparent}#nette-debug .nette-DumpPanel a abbr{font-family:sans-serif;color:#999}#nette-debug .nette-DumpPanel pre.nette-dump span{color:#c16549}</style> <h1>Dumped variables</h1> <div class="nette-inner nette-DumpPanel"> <?php foreach ($data as $item) { ?> <?php if ($item['title']) { ?> <h2><?php echo htmlspecialchars($item['title']); ?> </h2> <?php } ?> <table> <?php $i = 0; ?> <?php foreach ($item['dump'] as $key => $dump) { ?> <tr class="<?php echo $i++ % 2 ? 'nette-alt' : ''; ?> "> <th><?php echo htmlspecialchars($key); ?> </th> <td><?php echo $dump; ?> </td> </tr> <?php } ?> </table> <?php } ?> </div> <?php } elseif ($this->id === 'errors') { ?> <h1>Errors</h1> <?php $relative = isset($_SERVER['SCRIPT_FILENAME']) ? strtr(dirname(dirname($_SERVER['SCRIPT_FILENAME'])), '/', DIRECTORY_SEPARATOR) : NULL; ?> <div class="nette-inner"> <table> <?php $i = 0; foreach ($data as $item => $count) { list($message, $file, $line) = explode('|', $item); ?> <tr class="<?php echo $i++ % 2 ? 'nette-alt' : ''; ?> "> <td class="nette-right"><?php echo $count ? "{$count}×" : ''; ?> </td> <td><pre><?php echo htmlspecialchars($message), ' in ', Debugger::$editor ? '<a href="' . DebugHelpers::editorLink($file, $line) . '">' : '', htmlspecialchars($relative ? str_replace($relative, "...", $file) : $file), ':', $line, Debugger::$editor ? '</a>' : ''; ?> </pre></td> </tr> <?php } ?> </table> </div><?php } return ob_get_clean(); }
public function getPanel() { $this->disabled = TRUE; $s = ''; $h = 'htmlSpecialChars'; foreach ($this->queries as $i => $query) { list($sql, $params, $time, $rows, $connection, $source) = $query; $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && preg_match('#\\s*\\(?\\s*SELECT\\s#iA', $sql)) { try { $cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN'; $explain = $connection->queryArgs("{$cmd} {$sql}", $params)->fetchAll(); } catch (PDOException $e) { } } $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000); if ($explain) { static $counter; $counter++; $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-DbConnectionPanel-row-{$counter}'>explain ►</a>"; } $s .= '</td><td class="nette-DbConnectionPanel-sql">' . DatabaseHelpers::dumpSql(self::$maxLength ? Strings::truncate($sql, self::$maxLength) : $sql); if ($explain) { $s .= "<table id='nette-DbConnectionPanel-row-{$counter}' class='nette-collapsed'><tr>"; foreach ($explain[0] as $col => $foo) { $s .= "<th>{$h($col)}</th>"; } $s .= "</tr>"; foreach ($explain as $row) { $s .= "<tr>"; foreach ($row as $col) { $s .= "<td>{$h($col)}</td>"; } $s .= "</tr>"; } $s .= "</table>"; } if ($source) { $s .= DebugHelpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source'); } $s .= '</td><td>'; foreach ($params as $param) { $s .= Debugger::dump($param, TRUE); } $s .= '</td><td>' . $rows . '</td></tr>'; } return empty($this->queries) ? '' : '<style> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important } #nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style> <h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1> <div class="nette-inner nette-DbConnectionPanel"> <table> <tr><th>Time ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . ' </table> </div>'; }