Browse Source

Fixes #15216: Added `yii\web\ErrorHandler::$traceLine` to allow opening file at line clicked in IDE

tags/2.0.14
Гордиенко Владислав Юрьевич 7 years ago committed by Alexander Makarov
parent
commit
7cafa65ad2
  1. 2
      framework/CHANGELOG.md
  2. 8
      framework/views/errorHandler/callStackItem.php
  3. 10
      framework/web/ErrorHandler.php
  4. 11
      tests/framework/web/ErrorHandlerTest.php

2
framework/CHANGELOG.md

@ -3,7 +3,7 @@ Yii Framework 2 Change Log
2.0.14 under development
------------------------
- Enh #15216: Added `yii\web\ErrorHandler::$traceLine` to allow opening file at line clicked in IDE (vladis84)
- Enh #14488: Added support for X-Forwarded-Host to `yii\web\Request`, fixed `getServerPort()` usage (si294r, samdark)
- Enh #13019: Support JSON in SchemaBuilderTrait (zhukovra, undefinedor)
- Enh #15047: `yii\db\Query::select()` and `yii\db\Query::addSelect()` now check for duplicate column names (wapmorgan)

8
framework/views/errorHandler/callStackItem.php

@ -34,12 +34,14 @@
<?php for ($i = $begin; $i <= $end; ++$i): ?><div class="hover-line"></div><?php endfor; ?>
<div class="code">
<?php for ($i = $begin; $i <= $end; ++$i): ?><span class="lines-item"><?= (int) ($i + 1) ?></span><?php endfor; ?>
<pre><?php
<pre>
<?php
// fill empty lines with a whitespace to avoid rendering problems in opera
for ($i = $begin; $i <= $end; ++$i) {
echo (trim($lines[$i]) === '') ? " \n" : $handler->htmlEncode($lines[$i]);
echo (trim($lines[$i]) === '') ? " \n" : strtr($handler->traceLine, ['{file}' => $file, '{line}' => $i + 1, '{html}' => $handler->htmlEncode($lines[$i])]);
}
?></pre>
?>
</pre>
</div>
</div>
<?php endif; ?>

10
framework/web/ErrorHandler.php

@ -70,6 +70,16 @@ class ErrorHandler extends \yii\base\ErrorHandler
*/
public $displayVars = ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION'];
/**
* @var string placeholders to be be substituted.
* The placeholders are {file}, {line} and {text} and the string should be as follows.
*
* `File: {file} - Line: {line} - Text: {text}`
*
* @example <a href="netbeans://open?file={file}&line={line}">{html}</a>
* @since 2.0.14
*/
public $traceLine = '{html}';
/**
* Renders the exception.

11
tests/framework/web/ErrorHandlerTest.php

@ -38,6 +38,17 @@ class ErrorHandlerTest extends TestCase
Message: This message is displayed to end user
Exception: yii\web\NotFoundHttpException', $out);
}
public function testRenderCallStackItem()
{
$handler = Yii::$app->getErrorHandler();
$handler->traceLine = '<a href="netbeans://open?file={file}&line={line}">{html}</a>';
$file = \yii\BaseYii::getAlias('@yii/web/Application.php');
$out = $handler->renderCallStackItem($file, 63, \yii\web\Application::className(), null, null, null);
$this->assertContains('<a href="netbeans://open?file=' . $file . '&line=63">', $out);
}
}
class ErrorHandler extends \yii\web\ErrorHandler

Loading…
Cancel
Save