Permalink
Browse files

Added a plain text version of the exception formatting

  • Loading branch information...
1 parent 938d1c8 commit 0bc2007b0ca0df912d2e86bbdadd457528863c5d @rikh42 committed Feb 26, 2013
Showing with 45 additions and 0 deletions.
  1. +45 −0 errors/FlattenExceptionFormatter.php
@@ -41,6 +41,12 @@
*/
class FlattenExceptionFormatter
{
+
+ /**
+ * Turn a flattened Exception into HTML
+ * @param FlattenException $exception
+ * @return string
+ */
public static function formatException(FlattenException $exception)
{
$count = count($exception->getAllPrevious());
@@ -69,6 +75,45 @@ public static function formatException(FlattenException $exception)
}
+
+ /**
+ * Turn a flat exception into plain text
+ * @param FlattenException $exception
+ * @return string
+ */
+ public static function formatExceptionPlain(FlattenException $exception)
+ {
+ $count = count($exception->getAllPrevious());
+ $content = '';
+ foreach ($exception->toArray() as $position => $e)
+ {
+ $ind = $count - $position + 1;
+ $total = $count + 1;
+ $class = $e['class'];
+ $message = nl2br($e['message']);
+ $content .= "$ind/$total: $class: $message\n";
+ foreach ($e['trace'] as $i => $trace)
+ {
+ $content .= '- ';
+ if ($trace['function'])
+ {
+ $content .= sprintf('at %s%s%s()', $trace['class'], $trace['type'], $trace['function']);
+ }
+ if (isset($trace['file']) && isset($trace['line']))
+ {
+ $content .= sprintf('in %s line %s', $trace['file'], $trace['line']);
+ }
+ $content .= "\n";
+ }
+
+ $content .= "\n";
+ }
+
+ return $content;
+
+ }
+
+
public static function abbrClass($class)
{
$parts = explode('\\', $class);

0 comments on commit 0bc2007

Please sign in to comment.