8000 bug #20525 [TwigBundle] Give some love to exception pages (nicolas-gr… · symfony/symfony@6a6e330 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a6e330

Browse files
committed
bug #20525 [TwigBundle] Give some love to exception pages (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- [TwigBundle] Give some love to exception pages | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Before: ![before](https://cloud.githubusercontent.com/assets/243674/20304174/e4e0f492-aafc-11e6-8ca4-c76bea856f7a.png) After: ![after](https://cloud.githubusercontent.com/assets/243674/20304178/e8dcaae6-aafc-11e6-87a0-567be498fc6e.png) Commits ------- d8e9b6c [TwigBundle] Give some love to exception pages
2 parents c57d8ed + d8e9b6c commit 6a6e330

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getFilters()
5151
new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
5252
new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
5353
new \Twig_SimpleFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
54+
new \Twig_SimpleFilter('format_log_message', array($this, 'formatLogMessage'), array('is_safe' => array('html'))),
5455
new \Twig_SimpleFilter('file_link', array($this, 'getFileLink')),
5556
);
5657
}
@@ -151,7 +152,7 @@ public function fileExcerpt($file, $line, $srcContext = 3)
151152
}
152153

153154
for ($i = max($line - $srcContext, 1), $max = min($line + $srcContext, count($content)); $i <= $max; ++$i) {
154-
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><div class="anchor" id="line'.$i.'"></div><code>'.self::fixCodeMarkup($content[$i - 1]).'</code></li>';
155+
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><a class="anchor" name="line'.$i.'"></a><code>'.self::fixCodeMarkup($content[$i - 1]).'</code></li>';
155156
}
156157

157158
return '<ol start="'.max($line - $srcContext, 1).'">'.implode("\n", $lines).'</ol>';
@@ -183,9 +184,7 @@ public function formatFile($file, $line, $text = null)
183184
$text = "$text at line $line";
184185

185186
if (false !== $link = $this->getFileLink($file, $line)) {
186-
$flags = ENT_COMPAT | ENT_SUBSTITUTE;
187-
188-
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
187+
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset), $text);
189188
}
190189

191190
return $text;
@@ -215,6 +214,27 @@ public function formatFileFromText($text)
215214
}, $text);
216215
}
217216

217+
/**
218+
* @internal
219+
*/
220+
public function formatLogMessage($message, array $context)
221+
{
222+
if ($context && false !== strpos($message, '{')) {
223+
$replacements = array();
224+
foreach ($context as $key => $val) {
225+
if (is_scalar($val)) {
226+
$replacements['{'.$key.'}'] = $val;
227+
}
228+
}
229+
230+
if ($replacements) {
231+
$message = strtr($message, $replacements);
232+
}
233+
}
234+
235+
return htmlspecialchars($message, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset);
236+
}
237+
218238
/**
219239
* {@inheritdoc}
220240
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ol class="traces logs">
22
{% for log in logs %}
33
<li{% if log.priority >= 400 %} class="error"{% elseif log.priority >= 300 %} class="warning"{% endif %}>
4-
{{ log.priorityName }} - {{ log.message }}
4+
{{ log.priorityName }} - {{ log.message|format_log_message(log.context) }}
55
</li>
66
{% endfor %}
77
</ol>

src/Symfony/Component/VarDumper/Caster/ClassStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($identifier, $callable = null)
6464

6565
if ($f = $r-> 6293 getFileName()) {
6666
$this->attr['file'] = $f;
67-
$this->attr['line'] = $r->getStartLine() - substr_count($r->getDocComment(), "\n");
67+
$this->attr['line'] = $r->getStartLine();
6868
}
6969
}
7070

src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testClassStub()
119119

120120
$expectedDump = <<<'EODUMP'
121121
<foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp>
122-
<span class=sf-dump-index>0</span> => "<a href="%sFooInterface.php:8"><span class=sf-dump-str title="5 characters">hello</span></a>"
122+
<span class=sf-dump-index>0</span> => "<a href="%sFooInterface.php:10"><span class=sf-dump-str title="5 characters">hello</span></a>"
123123
</samp>]
124124
</bar>
125125
EODUMP;

0 commit comments

Comments
 (0)
0