8000 [Debug] Add link to the output of debug function · symfony/symfony@dadd2fe · GitHub
[go: up one dir, main page]

Skip to content

Commit dadd2fe

Browse files
committed
[Debug] Add link to the output of debug function
1 parent b4dcd50 commit dadd2fe

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

src/Symfony/Bundle/DebugBundle/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<service id="data_collector.dump" class="%data_collector.dump.class%">
1414
<tag name="data_collector" id="dump" template="@Debug/Profiler/dump.html.twig" />
1515
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
16+
<argument>%templating.helper.code.file_link_format%</argument>
1617
</service>
1718

1819
<service id="debug.dump_listener" class="%debug.dump_listener.class%">

src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@
1515
<b>dump()</b>
1616
</div>
1717
{% for dump in collector.getDumps('html') %}
18-
<div class="sf-toolbar-info-piece">
19-
in {% if dump.file %}<abbr title="{{ dump.file }}">{{ dump.name }}</abbr>{% else %}{{ dump.name }}{% endif %}
20-
line {{ dump.line }}:
21-
{{ dump.data|raw }}
22-
</div>
18+
<div class="sf-toolbar-info-piece">
19+
in
20+
{% if dump.file %}
21+
{% set link = dump.file|file_link(dump.line) }} %}
22+
{% if link %}
23+
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
24+
{% else %}
25+
<abbr title="{{ dump.file }}">{{ dump.name }}</abbr>
26+
{% endif %}
27+
{% else %}
28+
{{ dump.name }}
29+
{% endif %}
30+
line {{ dump.line }}:
31+
{{ dump.data|raw }}
32+
</div>
2333
{% endfor %}
2434
<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="var h = this.parentNode.innerHTML, rx=/<script>(.*?)<\/script>/g, s; while (s = rx.exec(h)) {eval(s[1]);};" />
2535
</div>
@@ -64,7 +74,17 @@
6474
<ul class="alt">
6575
{% for dump in collector.getDumps('html') %}
6676
<li class="sf-dump sf-reset">
67-
in {% if dump.file %}<abbr title="{{ dump.file }}">{{ dump.name }}</abbr>{% else %}{{ dump.name }}{% endif %}
77+
in
78+
{% if dump.line %}
79+
{% set link = dump.file|file_link(dump.line) }} %}
80+
{% if link %}
81+
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
82+
{% else %}
83+
<abbr title="{{ dump.file }}">{{ dump.name }}</abbr>
84+
{% endif %}
85+
{% else %}
86+
{{ dump.name }}
87+
{% endif %}
6888
line {{ dump.line }}:
6989
<a onclick="Sfjs.dump.toggle(this)">▶</a>
7090
<span class="sf-dump-compact">

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626
class DumpDataCollector extends DataCollector implements DataDumperInterface
2727
{
2828
private $stopwatch;
29+
private $fileLinkFormat;
2930
private $dataCount = 0;
3031
private $isCollected = true;
3132
private $clonesCount = 0;
3233
private $clonesIndex = 0;
3334
private $rootRefs;
3435

35-
public function __construct(Stopwatch $stopwatch = null)
36+
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null)
3637
{
3738
$this->stopwatch = $stopwatch;
39+
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3840

3941
// All clones share these properties by reference:
4042
$this->rootRefs = array(
@@ -213,7 +215,12 @@ public function __destruct()
213215
$dump['name'] = htmlspecialchars($dump['name'], ENT_QUOTES, 'UTF-8');
214216
$dump['file'] = htmlspecialchars($dump['file'], ENT_QUOTES, 'UTF-8');
215217
if ('' !== $dump['file']) {
216-
$dump['name'] = "<abbr title=\"{$dump['file']}\">{$dump['name']}</abbr>";
218+
if ($this->fileLinkFormat) {
219+
$link = strtr($this->fileLinkFormat, array('%f' => $dump['file'], '%l' => $dump['line']));
220+
$dump['name'] = sprintf('<a href="%s" title="%s">%s</a>', $link, $dump['file'], $dump['name']);
221+
} else {
222+
$dump['name'] = sprintf('<abbr title="%s">%s</abbr>', $dump['file'], $dump['name']);
223+
}
217224
}
218225
echo "\n<span class=\"sf-dump-meta\">{$dump['name']} on line {$dump['line']}:</span>";
219226
} else {

0 commit comments

Comments
 (0)
0