/**
  * 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;
 }
Esempio n. 2
0
 /**
  * Creates the error Response associated with the given Exception.
  *
  * @param \Exception $exception An \Exception instance
  *
  * @return Response A Response instance
  */
 public function createResponse(\Exception $exception)
 {
     // defaults
     $content = '';
     $title = '';
     // try and get decent values
     try {
         $code = 500;
         $title = 'We\'re sorry, but it looks like something went wrong.';
         $exception = FlattenException::create($exception);
         if (PHP_SAPI === 'cli') {
             // we are on the command line, so get the error in a clean format
             $content = FlattenExceptionFormatter::formatExceptionPlain($exception);
             // dump it out and exit with an error code
             echo $content;
             exit(1);
         } else {
             $content = $this->decorate(FlattenExceptionFormatter::formatException($exception), $title);
         }
     } catch (\Exception $e) {
         $title = 'We\'re sorry, but it looks like something went wrong.';
         $content = $this->decorate('', $title);
     }
     // build a response out of anything we got
     return new Response($content, $code);
 }