Преглед изворни кода

made the controller name in the WDT clickable

Fabien Potencier пре 14 година
родитељ
комит
0c8ff92ecd

+ 7 - 1
src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php

@@ -43,7 +43,13 @@ class RequestDataCollector extends BaseRequestDataCollector
         if (isset($this->controllers[$request])) {
             $controller = $this->controllers[$request];
             if (is_array($controller)) {
-                $this->data['controller'] = array(get_class($controller[0]), $controller[1]);
+                $r = new \ReflectionMethod($controller[0], $controller[1]);
+                $this->data['controller'] = array(
+                    'class'  => get_class($controller[0]),
+                    'method' => $controller[1],
+                    'file'   => $r->getFilename(),
+                    'line'   => $r->getStartLine(),
+                );
             } elseif ($controller instanceof \Closure) {
                 $this->data['controller'] = 'Closure';
             } else {

+ 28 - 14
src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

@@ -153,29 +153,43 @@ class CodeHelper extends Helper
     /**
      * Formats a file path.
      *
-     * @param  string  $file   An absolute file path
-     * @param  integer $line   The line number
-     * @param  string  $format The output format (txt or html)
-     * @param  string  $text   Use this text for the link rather than the file path
+     * @param  string  $file An absolute file path
+     * @param  integer $line The line number
+     * @param  string  $text Use this text for the link rather than the file path
      *
      * @return string
      */
-    public function formatFile($file, $line)
+    public function formatFile($file, $line, $text = null)
     {
-        $file = trim($file);
-        $fileStr = $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 (null === $text) {
+            $file = trim($file);
+            $fileStr = $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);
+            }
+
+            $text = "$fileStr line $line";
         }
 
-        if (!$this->fileLinkFormat) {
-            return "$file line $line";
+        if (false !== $link = $this->getFileLink($file, $line)) {
+            return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', $link, $text);
         }
 
-        $link = strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line));
+        return $text;
+    }
 
-        return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s line %s</a>', $link, $fileStr, $line);
+    /**
+     * Returns the link for a given file/line pair.
+     *
+     * @param  string  $file An absolute file path
+     * @param  integer $line The line number
+     *
+     * @return string A link of false
+     */
+    public function getFileLink($file, $line)
+    {
+        return $this->fileLinkFormat ? strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)) : false;
     }
 
     public function formatFileFromText($text)

+ 8 - 2
src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php

@@ -56,6 +56,7 @@ class TemplatingExtension extends \Twig_Extension
             'file_excerpt'          => new \Twig_Filter_Method($this, 'fileExcerpt', array('is_safe' => array('html'))),
             'format_file'           => new \Twig_Filter_Method($this, 'formatFile', array('is_safe' => array('html'))),
             'format_file_from_text' => new \Twig_Filter_Method($this, 'formatFileFromText', array('is_safe' => array('html'))),
+            'file_link'             => new \Twig_Filter_Method($this, 'getFileLink', array('is_safe' => array('html'))),
         );
     }
 
@@ -160,9 +161,14 @@ class TemplatingExtension extends \Twig_Extension
         return $this->container->get('templating.helper.code')->fileExcerpt($file, $line);
     }
 
-    public function formatFile($file, $line)
+    public function formatFile($file, $line, $text = null)
     {
-        return $this->container->get('templating.helper.code')->formatFile($file, $line);
+        return $this->container->get('templating.helper.code')->formatFile($file, $line, $text);
+    }
+
+    public function getFileLink($file, $line)
+    {
+        return $this->container->get('templating.helper.code')->getFileLink($file, $line);
     }
 
     public function formatFileFromText($text)

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

@@ -6,7 +6,7 @@
     {% endset %}
     {% set text %}
         {% spaceless %}
-            <span>{% if collector.controller.0 is defined %}{{ collector.controller.0|abbr_class }}::{{ collector.controller.1|abbr_class }}{% else %}{{ collector.controller }}{% endif %}</span>
+            <span>{% if collector.controller.class is defined %}{{ collector.controller.class|abbr_class }}::<a style="color: #2f2f2f" href="{{ collector.controller.file|file_link(collector.controller.line) }}">{{ collector.controller.method }}</a>{% else %}{{ collector.controller }}{% endif %}</span>
             <span style="margin: 0; padding: 0; color: #979696;">|</span>
             <span{{ not collector.route ? ' style="color:#a33"' : '' }}>{{ collector.route ? collector.route : 'NONE' }}</span>
             <span style="margin: 0; padding: 0; color: #979696;">|</span>