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 && self::$showLocation) { $trace = debug_backtrace(); $i = isset($trace[1]['class']) && $trace[1]['class'] === __CLASS__ ? 1 : 0; if (isset($trace[$i]['file'], $trace[$i]['line'])) { $output = substr_replace($output, ' <small>' . htmlspecialchars("in file {$trace[$i]['file']} on line {$trace[$i]['line']}", ENT_NOQUOTES) . '</small>', -8, 0); } } if (self::$consoleMode) { $output = htmlspecialchars_decode(strip_tags($output), ENT_NOQUOTES); } if ($return) { return $output; } else { echo $output; return $var; } }
/** * 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; } }