Example #1
0
 public static function dump($var, $return = FALSE)
 {
     if (!$return && self::$productionMode) {
         return $var;
     }
     $output = "<pre class=\"nette-dump\">" . NDebugHelpers::htmlDump($var) . "</pre>\n";
     if (!$return) {
         $trace = debug_backtrace();
         $i = NDebugHelpers::findTrace($trace, 'dump') ? 1 : 0;
         if (isset($trace[$i]['file'], $trace[$i]['line']) && is_file($trace[$i]['file'])) {
             $lines = file($trace[$i]['file']);
             preg_match('#dump\\((.*)\\)#', $lines[$trace[$i]['line'] - 1], $m);
             $output = substr_replace($output, ' title="' . htmlspecialchars((isset($m[0]) ? "{$m['0']} \n" : '') . "in file {$trace[$i]['file']} on line {$trace[$i]['line']}") . '"', 4, 0);
             if (self::$showLocation) {
                 $output = substr_replace($output, ' <small>in ' . NDebugHelpers::editorLink($trace[$i]['file'], $trace[$i]['line']) . ":{$trace[$i]['line']}</small>", -8, 0);
             }
         }
     }
     if (self::$consoleMode) {
         $output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES);
     }
     if ($return) {
         return $output;
     } else {
         echo $output;
         return $var;
     }
 }
Example #2
0
	/**
	 * 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\">" . NDebugHelpers::htmlDump($var) . "</pre>\n";

		if (!$return) {
			$trace = PHP_VERSION_ID < 50205 ? debug_backtrace() : debug_backtrace(FALSE);
			$item = ($tmp=NDebugHelpers::findTrace($trace, 'dump')) ? $tmp : NDebugHelpers::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 ' . NDebugHelpers::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], NDebugger::$consoleColors[$m[1]]) ? NDebugger::$consoleColors[$m[1]] : \'0\') . "m";
				'), $output);
			}
			$output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES);
		}

		if ($return) {
			return $output;

		} else {
			echo $output;
			return $var;
		}
	}
Example #3
0
 function getPanel()
 {
     $link = NDebugHelpers::editorLink($this->sourceFile, $this->sourceLine);
     return '<p><b>File:</b> ' . ($link ? '<a href="' . htmlspecialchars($link) . '">' : '') . htmlspecialchars($this->sourceFile) . ($link ? '</a>' : '') . '&nbsp; <b>Line:</b> ' . ($this->sourceLine ? $this->sourceLine : 'n/a') . '</p>' . ($this->sourceLine ? '<pre>' . NDebugHelpers::highlightFile($this->sourceFile, $this->sourceLine) . '</pre>' : '');
 }
Example #4
0
	public function getPanel()
	{
		$this->disabled = TRUE;
		$s = '';
		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&nbsp;&#x25ba;</a>";
			}

			$s .= '</td><td class="nette-DbConnectionPanel-sql">' . NDatabaseHelpers::dumpSql(self::$maxLength ? NStrings::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>' . htmlSpecialChars($col) . '</th>';
				}
				$s .= "</tr>";
				foreach ($explain as $row) {
					$s .= "<tr>";
					foreach ($row as $col) {
						$s .= '<td>' . htmlSpecialChars($col) . '</td>';
					}
					$s .= "</tr>";
				}
				$s .= "</table>";
			}
			if ($source) {
				$s .= NDebugHelpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source');
			}

			$s .= '</td><td>';
			foreach ($params as $param) {
				$s .= NDebugger::dump($param, TRUE);
			}

			$s .= '</td><td>' . $rows . '</td></tr>';
		}

		return empty($this->queries) ? '' :
			'<style class="nette-debug"> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important }
			#nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style>
			<h1 title="' . htmlSpecialChars($connection->getDsn()) . '">Queries: ' . count($this->queries)
			. ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . ', ' . htmlSpecialChars($this->name) . '</h1>
			<div class="nette-inner nette-DbConnectionPanel">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
			</table>
			</div>';
	}