[FrameworkBundle] fixed file detection and formatting in Code helper

This commit is contained in:
Fabien Potencier 2010-09-26 20:19:05 +02:00
parent 35ee15d131
commit b890c3429d

View File

@ -158,9 +158,11 @@ class CodeHelper extends Helper
*/ */
public function formatFile($file, $line) public function formatFile($file, $line)
{ {
if (0 === strpos($file, $this->rootDir)) { $file = trim($file);
$file = str_replace($this->rootDir, '', str_replace('\\', '/', $file)); $fileStr = $file;
$file = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', $this->rootDir, $file); if (0 === strpos($fileStr, $this->rootDir)) {
$fileStr = str_replace($this->rootDir, '', str_replace('\\', '/', $fileStr));
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', $this->rootDir, $fileStr);
} }
if (!$this->fileLinkFormat) { if (!$this->fileLinkFormat) {
@ -169,15 +171,15 @@ class CodeHelper extends Helper
$link = strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)); $link = strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line));
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s line %s</a>', $link, $file, $line); return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s line %s</a>', $link, $fileStr, $line);
} }
public function formatFileFromText($text) public function formatFileFromText($text)
{ {
$that = $this; $that = $this;
return preg_replace_callback('/(called|defined) in (.*?)(?: on)? line (\d+)/', function ($match) use ($that) { return preg_replace_callback('/in (.*?)(?: on|at)? line (\d+)/', function ($match) use ($that) {
return $match[1].' in '.$that->formatFile($match[2], $match[3]); return 'in '.$that->formatFile($match[1], $match[2]);
}, $text); }, $text);
} }