Skip to content

Commit fbd4a6f

Browse files
Added a default ide file link web view
1 parent c6f6e05 commit fbd4a6f

File tree

9 files changed

+107
-9
lines changed

9 files changed

+107
-9
lines changed

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ public function formatArgsAsText($args)
129129

130130
/**
131131
* Returns an excerpt of a code file around the given line number.
132+
* Set $srcContext to -1 for the whole file.
132133
*
133-
* @param string $file A file path
134-
* @param int $line The selected line number
134+
* @param string $file A file path
135+
* @param int $line The selected line number
136+
* @param int $srcContext The number of displayed line before and after
135137
*
136138
* @return string An HTML string
137139
*/
138-
public function fileExcerpt($file, $line)
140+
public function fileExcerpt($file, $line, $srcContext = 3)
139141
{
140142
if (is_readable($file)) {
141143
// highlight_file could throw warnings
@@ -146,11 +148,15 @@ public function fileExcerpt($file, $line)
146148
$content = preg_split('#<br />#', $code);
147149

148150
$lines = array();
149-
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; ++$i) {
150-
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><code>'.self::fixCodeMarkup($content[$i - 1]).'</code></li>';
151+
if (0 > $srcContext) {
152+
$srcContext = count($content);
151153
}
152154

153-
return '<ol start="'.max($line - 3, 1).'">'.implode("\n", $lines).'</ol>';
155+
for ($i = max($line - $srcContext, 1), $max = min($line + $srcContext, count($content)); $i <= $max; ++$i) {
156+
$lines[] = '<li id="line'.$i.'"'.($i == $line ? ' class="selected"' : '').'><code>'.self::fixCodeMarkup($content[$i - 1]).'</code></li>';
157+
}
158+
159+
return '<ol start="'.max($line - $srcContext, 1).'">'.implode("\n", $lines).'</ol>';
154160
}
155161
}
156162

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{% if dump.file %}
1515
{% set link = dump.file|file_link(dump.line) %}
1616
{% if link %}
17-
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
17+
<a href="{{ link }}#line{{ dump.line }}" title="{{ dump.file }}">{{ dump.name }}</a>
1818
{% else %}
1919
<abbr title="{{ dump.file }}">{{ dump.name }}</abbr>
2020
{% endif %}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getConfigTreeBuilder()
8787
->end()
8888
->end()
8989
->end()
90-
->scalarNode('ide')->defaultNull()->end()
90+
->scalarNode('ide')->defaultValue('symfony')->end()
9191
->booleanNode('test')->end()
9292
->scalarNode('default_locale')->defaultValue('en')->end()
9393
->arrayNode('trusted_hosts')

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function load(array $configs, ContainerBuilder $container)
100100
'macvim' => 'mvim://open?url=file://%%f&line=%%l',
101101
'emacs' => 'emacs://open?url=file://%%f&line=%%l',
102102
'sublime' => 'subl://open?url=file://%%f&line=%%l',
103+
'symfony' => '/_profiler/open?file=%%f&line=%%l#line%%l#"%kernel.root_dir%/=/',
103104
);
104105
$ide = $config['ide'];
105106

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

+28
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,34 @@ public function phpinfoAction()
394394
return new Response($phpinfo, 200, array('Content-Type' => 'text/html'));
395395
}
396396

397+
/**
398+
* Displays the source of a file.
399+
*
400+
* @return Response A Response instance
401+
*
402+
* @throws NotFoundHttpException
403+
*/
404+
public function openAction(Request $request)
405+
{
406+
if (null === $this->profiler) {
407+
throw new NotFoundHttpException('The profiler must be enabled.');
408+
}
409+
410+
$this->profiler->disable();
411+
412+
$file = $request->query->get('file');
413+
$line = $request->query->get('line');
414+
415+
if (0 === strpos($file, '/..') || !is_readable($filename)) {
416+
throw new NotFoundHttpException(sprintf('The file "%s" cannot be opened.', $file));
417+
}
418+
419+
return new Response($this->twig->render('@WebProfiler/Profiler/open.html.twig', array(
420+
'file' => $file,
421+
'line' => $line,
422+
)), 200, array('Content-Type' => 'text/html'));
423+
}
424+
397425
/**
398426
* Gets the Template Manager.
399427
*

src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<default key="_controller">web_profiler.controller.profiler:searchResultsAction</default>
2929
</route>
3030

31+
<route id="_open" path="/open">
32+
<default key="_controller">web_profiler.controller.profiler:openAction</default>
33+
</route>
34+
3135
<route id="_profiler" path="/{token}">
3236
<default key="_controller">web_profiler.controller.profiler:panelAction</default>
3337
</route>

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
{% if controller.class is defined -%}
270270
{%- if method|default(false) %}<span class="sf-toolbar-status sf-toolbar-redirection-method">{{ method }}</span>{% endif -%}
271271
{%- set link = controller.file|file_link(controller.line) %}
272-
{%- if link %}<a href="{{ link }}" title="{{ controller.file }}">{% else %}<span>{% endif %}
272+
{%- if link %}<a href="{{ link }}#line{{ controller.line }}" title="{{ controller.file }}">{% else %}<span>{% endif %}
273273

274274
{%- if route|default(false) -%}
275275
@{{ route }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{# Mixins
2+
========================================================================= #}
3+
{% set mixins = {
4+
'break_long_words': '-ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto;',
5+
'monospace_font': 'font-family: monospace; font-size: 13px; font-size-adjust: 0.5;',
6+
'sans_serif_font': 'font-family: Helvetica, Arial, sans-serif;',
7+
'subtle_border_and_shadow': 'background: #FFF; border: 1px solid #E0E0E0; box-shadow: 0px 0px 1px rgba(128, 128, 128, .2);'
8+
} %}
9+
10+
{# Normalization
11+
(normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css)
12+
========================================================================= #}
13+
html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{font-style:italic}h1{margin:.67em 0;font-size:2em}mark{color:#000;background:#ff0}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{height:0;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{margin:0;font:inherit;color:inherit}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid silver}legend{padding:0;border:0}textarea{overflow:auto}optgroup{font-weight:700}table{border-spacing:0;border-collapse:collapse}td,th{padding:0}
14+
15+
{# Basic styles
16+
========================================================================= #}
17+
html, body {
18+
height: 100%;
19+
width: 100%;
20+
}
21+
body {
22+
background-color: #F9F9F9;
23+
color: #222;
24+
display: flex;
25+
flex-direction: column;
26+
{{ mixins.sans_serif_font|raw }}
27+
font-size: 14px;
28+
line-height: 1.4;
29+
}
30+
#header {
31+
background-color: #222;
32+
}
33+
#header h1 {
34+
color: #FFF;
35+
font-weight: normal;
36+
font-size: 21px;
37+
margin: 0;
38+
padding: 10px 10px 8px;
39+
}
40+
41+
#open li.selected {
42+
background-color: #F0F0F0;
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends '@WebProfiler/Profiler/base.html.twig' %}
2+
3+
{% block head %}
4+
<style>
5+
{{ include('@WebProfiler/Profiler/open.css.twig') }}
6+
</style>
7+
{% endblock %}
8+
9+
{% block body %}
10+
<div id="header">
11+
<h1>{{ file }} <small>line {{ line }}</small></h1>
12+
</div>
13+
<div id="open">
14+
{{ filename|file_excerpt(line, -1, true) }}
15+
</div>
16+
{% endblock %}

0 commit comments

Comments
 (0)