Permalink
Browse files

Merge branch 'master' of git://github.com/nette/nette

  • Loading branch information...
2 parents 4f83c23 + 5eaf4c1 commit 4b52a68f191badfbef25abe8b8e49c3b954cff56 @insekticid committed Jan 9, 2012
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -32,7 +32,7 @@ class Bar
* Add custom panel.
* @param IBarPanel
* @param string
- * @return void
+ * @return Bar provides a fluent interface
*/
public function addPanel(IBarPanel $panel, $id = NULL)
{
@@ -43,6 +43,7 @@ public function addPanel(IBarPanel $panel, $id = NULL)
} while (isset($this->panels[$id]));
}
$this->panels[$id] = $panel;
+ return $this;
}
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -32,7 +32,7 @@ class BlueScreen
* Add custom panel.
* @param callback
* @param string
- * @return void
+ * @return BlueScreen provides a fluent interface
*/
public function addPanel($panel, $id = NULL)
{
@@ -41,6 +41,7 @@ public function addPanel($panel, $id = NULL)
} else {
$this->panels[$id] = $panel;
}
+ return $this;
}
@@ -75,12 +76,13 @@ public static function highlightFile($file, $line, $count = 15, $vars = array())
ini_set('highlight.string', '#080');
}
- $start = max(1, $line - floor($count / 2));
+ $start = max(1, $line - floor($count * 2/3));
$source = @file_get_contents($file); // intentionally @
if (!$source) {
return;
}
+ $sourcex = explode("\n", $source);
$source = explode("\n", highlight_string($source, TRUE));
$spans = 1;
$out = $source[0]; // <code><span color=highlight.html>
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -44,6 +44,9 @@
/** @var string URL pattern mask to open editor */
public static $editor = 'editor://open/?file=%file&line=%line';
+ /** @var string command to open browser (use 'start ""' in Windows) */
+ public static $browser;
+
/********************* Debugger::dump() ****************d*g**/
/** @var int how many nested levels of array/object properties display {@link Debugger::dump()} */
@@ -200,38 +203,11 @@ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
if (is_bool($mode)) {
self::$productionMode = $mode;
- } elseif (is_string($mode)) { // IP addresses
- $mode = preg_split('#[,\s]+#', "$mode 127.0.0.1 ::1");
- }
-
- if (is_array($mode)) { // IP addresses whitelist detection
- self::$productionMode = !isset($_SERVER['REMOTE_ADDR']) || !in_array($_SERVER['REMOTE_ADDR'], $mode, TRUE);
- }
-
- if (self::$productionMode === self::DETECT) {
- if (isset($_SERVER['SERVER_ADDR']) || isset($_SERVER['LOCAL_ADDR'])) { // IP address based detection
- $addrs = array();
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { // proxy server detected
- $addrs = preg_split('#,\s*#', $_SERVER['HTTP_X_FORWARDED_FOR']);
- }
- if (isset($_SERVER['REMOTE_ADDR'])) {
- $addrs[] = $_SERVER['REMOTE_ADDR'];
- }
- $addrs[] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
- self::$productionMode = FALSE;
- foreach ($addrs as $addr) {
- $oct = explode('.', $addr);
- if ($addr !== '::1' && (count($oct) !== 4 || ($oct[0] !== '10' && $oct[0] !== '127' && ($oct[0] !== '172' || $oct[1] < 16 || $oct[1] > 31)
- && ($oct[0] !== '169' || $oct[1] !== '254') && ($oct[0] !== '192' || $oct[1] !== '168')))
- ) {
- self::$productionMode = TRUE;
- break;
- }
- }
-
- } else {
- self::$productionMode = !self::$consoleMode;
- }
+ } elseif ($mode !== self::DETECT || self::$productionMode === NULL) { // IP addresses or computer names whitelist detection
+ $mode = is_string($mode) ? preg_split('#[,\s]+#', $mode) : array($mode);
+ $mode[] = '127.0.0.1';
+ $mode[] = '::1';
+ self::$productionMode = !in_array(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'), $mode, TRUE);
}
// logging configuration
@@ -300,7 +276,7 @@ public static function isEnabled()
* Logs message or exception to file (if not disabled) and sends email notification (if enabled).
* @param string|Exception
* @param int one of constant Debugger::INFO, WARNING, ERROR (sends email), CRITICAL (sends email)
- * @return void
+ * @return string logged error filename
*/
public static function log($message, $priority = self::INFO)
{
@@ -313,17 +289,18 @@ public static function log($message, $priority = self::INFO)
if ($message instanceof \Exception) {
$exception = $message;
- $message = "PHP Fatal error: "
- . ($message instanceof Nette\FatalErrorException
- ? $exception->getMessage()
- : "Uncaught exception " . get_class($exception) . " with message '" . $exception->getMessage() . "'")
+ $message = ($message instanceof Nette\FatalErrorException
+ ? 'Fatal error: ' . $exception->getMessage()
+ : get_class($exception) . ": " . $exception->getMessage())
. " in " . $exception->getFile() . ":" . $exception->getLine();
$hash = md5($exception /*5.2*. (method_exists($exception, 'getPrevious') ? $exception->getPrevious() : (isset($exception->previous) ? $exception->previous : ''))*/);
- $exceptionFilename = "exception " . @date('Y-m-d H-i-s') . " $hash.html";
+ $exceptionFilename = "exception-" . @date('Y-m-d-H-i-s') . "-$hash.html";
foreach (new \DirectoryIterator(self::$logDirectory) as $entry) {
if (strpos($entry, $hash)) {
- $exceptionFilename = NULL; break;
+ $exceptionFilename = $entry;
+ $saved = TRUE;
+ break;
}
}
}
@@ -335,13 +312,17 @@ public static function log($message, $priority = self::INFO)
!empty($exceptionFilename) ? ' @@ ' . $exceptionFilename : NULL
), $priority);
- if (!empty($exceptionFilename) && $logHandle = @fopen(self::$logDirectory . '/'. $exceptionFilename, 'w')) {
- ob_start(); // double buffer prevents sending HTTP headers in some PHP
- ob_start(function($buffer) use ($logHandle) { fwrite($logHandle, $buffer); }, 1);
- self::$blueScreen->render($exception);
- ob_end_flush();
- ob_end_clean();
- fclose($logHandle);
+ if (!empty($exceptionFilename)) {
+ $exceptionFilename = self::$logDirectory . '/' . $exceptionFilename;
+ if (empty($saved) && $logHandle = @fopen($exceptionFilename, 'w')) {
+ ob_start(); // double buffer prevents sending HTTP headers in some PHP
+ ob_start(function($buffer) use ($logHandle) { fwrite($logHandle, $buffer); }, 1);
+ self::$blueScreen->render($exception);
+ ob_end_flush();
+ ob_end_clean();
+ fclose($logHandle);
+ }
+ return strtr($exceptionFilename, '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
}
}
@@ -408,6 +389,12 @@ public static function _exceptionHandler(\Exception $exception)
} else {
if (self::$consoleMode) { // dump to console
echo "$exception\n";
+ if ($file = self::log($exception)) {
+ echo "(stored in $file)\n";
+ if (self::$browser) {
+ exec(self::$browser . ' ' . escapeshellarg($file));
+ }
+ }
} elseif (self::isHtmlMode()) { // dump to browser
self::$blueScreen->render($exception);
@@ -416,7 +403,10 @@ public static function _exceptionHandler(\Exception $exception)
}
} elseif (!self::fireLog($exception, self::ERROR)) { // AJAX or non-HTML mode
- self::log($exception);
+ $file = self::log($exception);
+ if (!headers_sent()) {
+ header("X-Nette-Error-Log: $file");
+ }
}
}
@@ -588,7 +578,7 @@ public static function dump($var, $return = FALSE)
}
if (self::$consoleMode) {
- $output = htmlspecialchars_decode(strip_tags($output), ENT_NOQUOTES);
+ $output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES);
}
if ($return) {
@@ -663,7 +653,7 @@ private static function isHtmlMode()
/** @deprecated */
public static function addPanel(IBarPanel $panel, $id = NULL)
{
- self::$bar->addPanel($panel, $id);
+ return self::$bar->addPanel($panel, $id);
}
}
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -192,7 +192,7 @@ public static function htmlDump(&$var, $level = 0)
public static function clickableDump($dump)
{
return '<pre class="nette-dump">' . preg_replace_callback(
- '#^( *)((?>[^(]{1,200}))\((\d+)\) <code>#m',
+ '#^( *)((?>[^(\r\n]{1,200}))\((\d+)\) <code>#m',
function ($m) {
return "$m[1]<a href='#' rel='next'>$m[2]($m[3]) "
. (trim($m[1]) || $m[3] < 7
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -43,8 +43,7 @@ $title = ($exception instanceof Nette\FatalErrorException && isset($errorTypes[$
$expandPath = NETTE_DIR . DIRECTORY_SEPARATOR; // . 'Utils' . DIRECTORY_SEPARATOR . 'Object';
$counter = 0;
-?><!-- "' --></script></style></pre></xmp></table>
-<!DOCTYPE html>
+?><!DOCTYPE html><!-- "' --></script></style></pre></xmp></table>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@@ -312,6 +311,7 @@ $counter = 0;
<?php foreach ($panels as $panel): ?>
<?php $panel = call_user_func($panel, $ex); if (empty($panel['tab']) || empty($panel['panel'])) continue; ?>
+ <?php if (!empty($panel['bottom'])) { continue; } ?>
<div class="panel">
<h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>"><?php echo htmlSpecialChars($panel['tab']) ?> <abbr>&#x25bc;</abbr></a></h2>
@@ -418,8 +418,10 @@ $counter = 0;
+ <?php $bottomPanels = array() ?>
<?php foreach ($panels as $panel): ?>
<?php $panel = call_user_func($panel, NULL); if (empty($panel['tab']) || empty($panel['panel'])) continue; ?>
+ <?php if (!empty($panel['bottom'])) { $bottomPanels[] = $panel; continue; } ?>
<div class="panel">
<h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>"><?php echo htmlSpecialChars($panel['tab']) ?> <abbr>&#x25ba;</abbr></a></h2>
@@ -530,6 +532,18 @@ $counter = 0;
</div></div>
+
+ <?php foreach ($bottomPanels as $panel): ?>
+ <div class="panel">
+ <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>"><?php echo htmlSpecialChars($panel['tab']) ?> <abbr>&#x25bc;</abbr></a></h2>
+
+ <div id="netteBsPnl<?php echo $counter ?>" class="inner">
+ <?php echo $panel['panel'] ?>
+ </div></div>
+ <?php endforeach ?>
+
+
+
<ul>
<li>Report generated at <?php echo @date('Y/m/d H:i:s', Debugger::$time) ?></li>
<?php if (preg_match('#^https?://#', Debugger::$source)): ?>
@@ -2,7 +2,7 @@
* NetteQ
*
* This file is part of the Nette Framework.
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004, 2012 David Grudl (http://davidgrudl.com)
*/
var Nette = Nette || {};
View
@@ -3,7 +3,7 @@
/**
* This file is part of the Nette Framework (http://nette.org)
*
- * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
@@ -95,7 +95,7 @@ public static function el($name = NULL, $attrs = NULL)
}
$this->name = $name;
- $this->isEmpty = $isEmpty === NULL ? isset(self::$emptyElements[$name]) : (bool) $isEmpty;
+ $this->isEmpty = $isEmpty === NULL ? isset(static::$emptyElements[$name]) : (bool) $isEmpty;
return $this;
}
@@ -508,7 +508,7 @@ public function removeChildren()
final public function startTag()
{
if ($this->name) {
- return '<' . $this->name . $this->attributes() . (self::$xhtml && $this->isEmpty ? ' />' : '>');
+ return '<' . $this->name . $this->attributes() . (static::$xhtml && $this->isEmpty ? ' />' : '>');
} else {
return '';
@@ -544,7 +544,7 @@ public function removeChildren()
continue;
} elseif ($value === TRUE) {
- if (self::$xhtml) {
+ if (static::$xhtml) {
$s .= ' ' . $key . '="' . $key . '"';
} else {
$s .= ' ' . $key;
Oops, something went wrong.

0 comments on commit 4b52a68

Please sign in to comment.