Преглед на файлове

[FrameworkBundle] made exception controller embeddable

Fabien Potencier преди 14 години
родител
ревизия
eb66e0dc00

+ 5 - 2
src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php

@@ -24,11 +24,13 @@ class ExceptionController extends Controller
     /**
      * Converts an Exception to a Response.
      *
-     * @param ExceptionManager $manager An ExceptionManager instance
+     * @param ExceptionManager $manager  An ExceptionManager instance
+     * @param string           $format   The format to use for rendering (html, xml, ...)
+     * @param Boolean          $embedded Whether the rendered Response will be embedded or not
      *
      * @throws \InvalidArgumentException When the exception template does not exist
      */
-    public function exceptionAction(ExceptionManager $manager, $format)
+    public function exceptionAction(ExceptionManager $manager, $format, $embedded = false)
     {
         $this['request']->setRequestFormat($format);
 
@@ -43,6 +45,7 @@ class ExceptionController extends Controller
                 'manager'        => $manager,
                 'managers'       => $manager->getLinkedManagers(),
                 'currentContent' => $currentContent,
+                'embedded'       => $embedded,
             )
         );
         $response->setStatusCode($manager->getStatusCode());

Файловите разлики са ограничени, защото са твърде много
+ 36 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception.css


Файловите разлики са ограничени, защото са твърде много
+ 48 - 74
src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.php


+ 35 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.php

@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $view->getCharset() ?>"/>
+        <title><?php echo htmlspecialchars($manager->getMessage(), ENT_QUOTES, $view->getCharset()) ?> (<?php echo $manager->getStatusCode() ?> <?php echo $manager->getStatusText() ?>)</title>
+        <style type="text/css">
+            html { background: #eee }
+            body { font: 11px Verdana, Arial, sans-serif; color: #333 }
+
+            <?php echo $view->render('FrameworkBundle:Exception:styles') ?>
+        </style>
+        <script type="text/javascript">
+            function toggle(id, clazz) {
+                el = document.getElementById(id);
+                current = el.style.display
+
+                if (clazz) {
+                    var tags = document.getElementsByTagName('*');
+                    for (i = 0; i < tags.length; i++) {
+                        if (tags[i].className == clazz) {
+                            tags[i].style.display = 'none';
+                        }
+                    }
+                }
+
+                el.style.display = current == 'none' ? 'block' : 'none';
+            }
+        </script>
+    </head>
+    <body>
+        <center>
+            <?php echo $view['slots']->get('_content') ?>
+        </center>
+    </body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 41
src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/styles.php


+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/trace.php

@@ -2,7 +2,7 @@
     at <strong><abbr title="<?php echo $trace['class'] ?>"><?php echo $trace['short_class'] ?></abbr><?php echo $trace['type'] ?><?php echo $trace['function'] ?></strong>(<?php echo $view['code']->formatArgs($trace['args']) ?>)<br />
 <?php endif; ?>
 <?php if ($trace['file'] && $trace['line']): ?>
-    in <em><?php echo $view['code']->formatFile($trace['file'], $trace['line']) ?></em> line <?php echo $trace['line'] ?>
+    in <em><?php echo $view['code']->formatFile($trace['file'], $trace['line']) ?></em>
     <a href="#" onclick="toggle('trace_<?php echo $prefix.'_'.$i ?>'); return false;">&raquo;</a><br />
     <ul class="code" id="trace_<?php echo $prefix.'_'.$i ?>" style="display: <?php echo 0 === $i ? 'block' : 'none' ?>">
         <?php echo $view['code']->fileExcerpt($trace['file'], $trace['line']) ?>

+ 11 - 2
src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

@@ -162,12 +162,21 @@ class CodeHelper extends Helper
         }
 
         if (!$this->fileLinkFormat) {
-            return $file;
+            return "$file line $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</a>', $link, $file);
+        return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s line %s</a>', $link, $file, $line);
+    }
+
+    public function formatFileFromText($text)
+    {
+        $that = $this;
+
+        return preg_replace_callback('/(called|defined) in (.*?)(?: on)? line (\d+)/', function ($match) use ($that) {
+            return $match[1].' in '.$that->formatFile($match[2], $match[3]);
+        }, $text);
     }
 
     /**