Browse Source

Display debug toolbar on error pages.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
f72c451c86
  1. 3
      framework/yii/base/Application.php
  2. 5
      framework/yii/base/ErrorHandler.php
  3. 10
      framework/yii/views/errorHandler/callStackItem.php
  4. 21
      framework/yii/views/errorHandler/error.php
  5. 37
      framework/yii/views/errorHandler/exception.php
  6. 12
      framework/yii/views/errorHandler/previousException.php

3
framework/yii/base/Application.php

@ -475,6 +475,8 @@ abstract class Application extends Module
*/ */
public function handleFatalError() public function handleFatalError()
{ {
unset($this->_memoryReserve);
// load ErrorException manually here because autoloading them will not work // load ErrorException manually here because autoloading them will not work
// when error occurs while autoloading a class // when error occurs while autoloading a class
if (!class_exists('\\yii\\base\\Exception', false)) { if (!class_exists('\\yii\\base\\Exception', false)) {
@ -487,7 +489,6 @@ abstract class Application extends Module
$error = error_get_last(); $error = error_get_last();
if (ErrorException::isFatalError($error)) { if (ErrorException::isFatalError($error)) {
unset($this->_memoryReserve);
$exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
// use error_log because it's too late to use Yii log // use error_log because it's too late to use Yii log
error_log($exception); error_log($exception);

5
framework/yii/base/ErrorHandler.php

@ -192,11 +192,16 @@ class ErrorHandler extends Component
*/ */
public function renderFile($_file_, $_params_) public function renderFile($_file_, $_params_)
{ {
$_params_['handler'] = $this;
if ($this->exception instanceof ErrorException) {
ob_start(); ob_start();
ob_implicit_flush(false); ob_implicit_flush(false);
extract($_params_, EXTR_OVERWRITE); extract($_params_, EXTR_OVERWRITE);
require(Yii::getAlias($_file_)); require(Yii::getAlias($_file_));
return ob_get_clean(); return ob_get_clean();
} else {
return Yii::$app->getView()->renderFile($_file_, $_params_, $this);
}
} }
/** /**

10
framework/yii/views/errorHandler/callStackItem.php

@ -8,19 +8,19 @@
* @var string[] $lines * @var string[] $lines
* @var integer $begin * @var integer $begin
* @var integer $end * @var integer $end
* @var \yii\base\ErrorHandler $this * @var \yii\base\ErrorHandler $handler
*/ */
?> ?>
<li class="<?php if (!$this->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item" <li class="<?php if (!$handler->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item"
data-line="<?php echo (int)($line - $begin); ?>"> data-line="<?php echo (int)($line - $begin); ?>">
<div class="element-wrap"> <div class="element-wrap">
<div class="element"> <div class="element">
<span class="item-number"><?php echo (int)$index; ?>.</span> <span class="item-number"><?php echo (int)$index; ?>.</span>
<span class="text"><?php if ($file !== null) echo 'in ' . $this->htmlEncode($file); ?></span> <span class="text"><?php if ($file !== null) echo 'in ' . $handler->htmlEncode($file); ?></span>
<?php if ($method !== null): ?> <?php if ($method !== null): ?>
<span class="call"> <span class="call">
<?php if ($file !== null) echo '&ndash;' ?> <?php if ($file !== null) echo '&ndash;' ?>
<?php if ($class !== null) echo $this->addTypeLinks($class) . '::'; ?><?php echo $this->addTypeLinks($method . '()'); ?> <?php if ($class !== null) echo $handler->addTypeLinks($class) . '::'; ?><?php echo $handler->addTypeLinks($method . '()'); ?>
</span> </span>
<?php endif; ?> <?php endif; ?>
<span class="at"><?php if ($line !== null) echo 'at line'; ?></span> <span class="at"><?php if ($line !== null) echo 'at line'; ?></span>
@ -36,7 +36,7 @@
<pre><?php <pre><?php
// fill empty lines with a whitespace to avoid rendering problems in opera // fill empty lines with a whitespace to avoid rendering problems in opera
for ($i = $begin; $i <= $end; ++$i) { for ($i = $begin; $i <= $end; ++$i) {
echo (trim($lines[$i]) == '') ? " \n" : $this->htmlEncode($lines[$i]); echo (trim($lines[$i]) == '') ? " \n" : $handler->htmlEncode($lines[$i]);
} }
?></pre> ?></pre>
</div> </div>

21
framework/yii/views/errorHandler/error.php

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @var \Exception $exception * @var \Exception $exception
* @var \yii\base\ErrorHandler $this * @var \yii\base\ErrorHandler $handler
*/ */
$title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception));
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -50,16 +50,17 @@ $title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exceptio
</head> </head>
<body> <body>
<h1><?php echo $title?></h1> <h1><?php echo $title?></h1>
<h2><?php echo nl2br($this->htmlEncode($exception->getMessage()))?></h2> <h2><?php echo nl2br($handler->htmlEncode($exception->getMessage()))?></h2>
<p> <p>
The above error occurred while the Web server was processing your request. The above error occurred while the Web server was processing your request.
</p> </p>
<p> <p>
Please contact us if you think this is a server error. Thank you. Please contact us if you think this is a server error. Thank you.
</p> </p>
<div class="version"> <div class="version">
<?php echo date('Y-m-d H:i:s', time())?> <?php echo date('Y-m-d H:i:s', time())?>
</div> </div>
<?php if (method_exists($this, 'endBody')) $this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?>
</body> </body>
</html> </html>

37
framework/yii/views/errorHandler/exception.php

File diff suppressed because one or more lines are too long

12
framework/yii/views/errorHandler/previousException.php

@ -1,7 +1,7 @@
<?php <?php
/** /**
* @var \yii\base\Exception $exception * @var \yii\base\Exception $exception
* @var \yii\base\ErrorHandler $this * @var \yii\base\ErrorHandler $handler
*/ */
?> ?>
<div class="previous"> <div class="previous">
@ -9,13 +9,13 @@
<h2> <h2>
<span>Caused by:</span> <span>Caused by:</span>
<?php if ($exception instanceof \yii\base\Exception): ?> <?php if ($exception instanceof \yii\base\Exception): ?>
<span><?php echo $this->htmlEncode($exception->getName()); ?></span> &ndash; <span><?php echo $handler->htmlEncode($exception->getName()); ?></span> &ndash;
<?php echo $this->addTypeLinks(get_class($exception)); ?> <?php echo $handler->addTypeLinks(get_class($exception)); ?>
<?php else: ?> <?php else: ?>
<span><?php echo $this->htmlEncode(get_class($exception)); ?></span> <span><?php echo $handler->htmlEncode(get_class($exception)); ?></span>
<?php endif; ?> <?php endif; ?>
</h2> </h2>
<h3><?php echo $this->htmlEncode($exception->getMessage()); ?></h3> <h3><?php echo $handler->htmlEncode($exception->getMessage()); ?></h3>
<p>in <span class="file"><?php echo $exception->getFile(); ?></span> at line <span class="line"><?php echo $exception->getLine(); ?></span></p> <p>in <span class="file"><?php echo $exception->getFile(); ?></span> at line <span class="line"><?php echo $exception->getLine(); ?></span></p>
<?php echo $this->renderPreviousExceptions($exception); ?> <?php echo $handler->renderPreviousExceptions($exception); ?>
</div> </div>

Loading…
Cancel
Save