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

This commit is contained in:
Гордиенко Владислав Юрьевич
2018-02-08 00:36:29 +05:00
committed by Alexander Makarov
parent e9bec0d246
commit 7cafa65ad2
4 changed files with 27 additions and 4 deletions

View File

@ -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)

View File

@ -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; ?>

View File

@ -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.

View File

@ -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