Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to config the trace file and line number #162

Merged
merged 14 commits into from Nov 10, 2016
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@ Yii Framework 2 debug extension Change Log
- Enh #97: Added AJAX requests handling (bashkarev)
- Bug #61: Fixed toolbar not to be cached by using renderDynamic (dynasource)
- Bug #160: Remove height as it prevents the background from stretching, causing unreadable overlapping texts over background (dynasource)
- Enh #162: Added ability to config the trace file and line number (thiagotalma)

2.0.6 March 17, 2016
--------------------
Expand Down
17 changes: 17 additions & 0 deletions Module.php
Expand Up @@ -91,6 +91,23 @@ class Module extends \yii\base\Module implements BootstrapInterface
* You may want to enable the debug logs if you want to investigate how the debug module itself works.
*/
public $enableDebugLogs = false;
/**
* @var mixed the string with placeholders to be be substituted or an anonymous function that returns the trace line string.
Copy link
Member

@dynasource dynasource Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its unclear how this string should look like?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, an example would be good.

* The placeholders are {file}, {line} and {text} and the string should be as follows,
*
* `File: {file} - Line: {line} - Text: {text}`
*
* The signature of the anonymous function should be as follows,
*
* ```php
* function($trace, $panel) {
* // compute line string
* return $line;
* }
* ```
* @since 2.0.7
*/
public $traceLink;

/**
* @var string Yii logo URL
Expand Down
24 changes: 24 additions & 0 deletions Panel.php
Expand Up @@ -114,4 +114,28 @@ public function getUrl($additionalParams = null)

return Url::toRoute($route);
}

/**
* @param array $options The array with trace
*
* @return string the trace line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing @SInCE

* @since 2.0.7
*/
public function traceLink($options)
{
if (!isset($options['text'])) {
$options['text'] = "{$options['file']}:{$options['line']}";
}
if ($this->module->traceLink === null) {
return $options['text'];
}
if (is_callable($this->module->traceLink)) {
return call_user_func($this->module->traceLink, $options, $this);
}
if (is_string($this->module->traceLink)) {
return strtr($this->module->traceLink, ['{file}' => $options['file'], '{line}' => $options['line'], '{text}' => $options['text']]);
}

return null;
}
}
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -53,3 +53,25 @@ return [

You will see a debugger toolbar showing at the bottom of every page of your application.
You can click on the toolbar to see more detailed debug information.


Open Files in IDE
-----

You can create a link to open files in your favorite IDE with this configuration:

```php
return [
'bootstrap' => ['debug'],
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
'traceLink' => '<a href="phpstorm://open?url={file}&line={line}">{file}:{line}</a>',
],
// ...
],
...
];
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest putting common IDE strings here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samdark In fact, there is no a list of possible settings per IDE.

The user is who sets the string when it does the setup in the operating system. There is a link that talks about this in the example I quoted: https://pla.nette.org/en/how-open-files-in-ide-from-debugger

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, shortly described at #144 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example symfony

You must make some changes to your OS, see this example: https://github.com/aik099/PhpStormProtocol
6 changes: 3 additions & 3 deletions views/default/panels/db/detail.php
Expand Up @@ -57,8 +57,8 @@
if (!empty($data['trace'])) {
$query .= Html::ul($data['trace'], [
'class' => 'trace',
'item' => function ($trace) {
return "<li>{$trace['file']} ({$trace['line']})</li>";
'item' => function ($trace) use ($panel) {
return '<li>' . $panel->traceLink($trace) . '</li>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if set 'traceLink' => 'phpstorm://open?url={file}&line={line}', this not link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bashkarev really! my bad....
fixed in README

},
]);
}
Expand All @@ -75,7 +75,7 @@

return $query;
},
'format' => 'html',
'format' => 'raw',
'options' => [
'width' => '60%',
],
Expand Down
8 changes: 4 additions & 4 deletions views/default/panels/log/detail.php
Expand Up @@ -55,19 +55,19 @@
'category',
[
'attribute' => 'message',
'value' => function ($data) {
'value' => function ($data) use ($panel) {
$message = Html::encode(is_string($data['message']) ? $data['message'] : VarDumper::export($data['message']));
if (!empty($data['trace'])) {
$message .= Html::ul($data['trace'], [
'class' => 'trace',
'item' => function ($trace) {
return "<li>{$trace['file']} ({$trace['line']})</li>";
'item' => function ($trace) use ($panel) {
return '<li>' . $panel->traceLink($trace) . '</li>';
}
]);
};
return $message;
},
'format' => 'html',
'format' => 'raw',
'options' => [
'width' => '50%',
],
Expand Down