static function display ($exception, ResponseInterface $response = null)
  {
    // For HTML pages, output the error popup

    if (strpos (get ($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
      ob_start ();
      ErrorConsoleRenderer::renderStyles ();
      $stackTrace = self::getStackTrace ($exception->getPrevious () ?: $exception);
      ErrorConsoleRenderer::renderPopup ($exception, self::$appName, $stackTrace);
      $popup = ob_get_clean ();

      // PSR-7 output

      if ($response) {
        $response->getBody ()->write ($popup);
        return $response->withStatus (500);
      }

      // Direct output

      echo $popup;
    }

    // For other content types, output a plain text message, replacing any existing response content
    else {

      // PSR-7 output

      if ($response) {
        $response->getBody ()->write ($exception->getMessage ());
        if (self::$devEnv)
          $response->getBody ()->write ("\n\nStack trace:\n" . $exception->getTraceAsString ());
        return $response
          ->withoutHeader ('Content-Type')
          ->withHeader ('Content-Type', 'text-plain')
          ->withStatus (500);
      }

      // Direct output

      header ("Content-Type: text/plain");
      http_response_code (500);
      echo $exception->getMessage ();
      if (self::$devEnv)
        echo "\n\nStack trace:\n" . $exception->getTraceAsString ();
    }
    return null;
  }
static function display ($exception, ResponseInterface $response = null)
  {
    // For HTML pages, output the error popup

    if (strpos (get ($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
      ob_start ();
      ErrorConsoleRenderer::renderStyles ();
      $stackTrace = self::getStackTrace ($exception->getPrevious () ?: $exception);
      ErrorConsoleRenderer::renderPopup ($exception, self::$appName, $stackTrace);
      $popup = ob_get_clean ();

      // PSR-7 output

      if ($response) {
        $response->getBody ()->write ($popup);
        return $response->withStatus (500);
      }

      // Direct output

      echo $popup;
    }

    // For other content types, output a plain text message, replacing any existing response content
    else {

      // PSR-7 output

      if ($response) {
        $response->getBody ()->write ($exception->getMessage ());
        if (self::$devEnv)
          $response->getBody ()->write ("\n\nStack trace:\n" . $exception->getTraceAsString ());
        return $response
          ->withoutHeader ('Content-Type')
          ->withHeader ('Content-Type', 'text-plain')
          ->withStatus (500);
      }

      // Direct output

      header ("Content-Type: text/plain");
      http_response_code (500);
      echo $exception->getMessage ();
      if (self::$devEnv)
        echo "\n\nStack trace:\n" . $exception->getTraceAsString ();
    }
    return null;
  }
static function display ( $ exception , ResponseInterface $ response = null ) { // For HTML pages, output the error popup if ( strpos ( get ( $ _SERVER , 'HTTP_ACCEPT' ) , 'text/html' ) !== false ) { ob_start ( ) ; ErrorConsoleRenderer :: renderStyles ( ) ; $ stackTrace = self :: getStackTrace ( $ exception -> getPrevious ( ) ? : $ exception ) ; ErrorConsoleRenderer :: renderPopup ( $ exception , self :: $ appName , $ stackTrace ) ; $ popup = ob_get_clean ( ) ; // PSR-7 output if ( $ response ) { $ response -> getBody ( ) -> write ( $ popup ) ; return $ response -> withStatus ( 500 ) ; } // Direct output echo $ popup ; } // For other content types, output a plain text message, replacing any existing response content else { // PSR-7 output if ( $ response ) { $ response -> getBody ( ) -> write ( $ exception -> getMessage ( ) ) ; if ( self :: $ devEnv ) $ response -> getBody ( ) -> write ( "\n\nStack trace:\n" . $ exception -> getTraceAsString ( ) ) ; return $ response -> withoutHeader ( 'Content-Type' ) -> withHeader ( 'Content-Type' , 'text-plain' ) -> withStatus ( 500 ) ; } // Direct output header ( "Content-Type: text/plain" ) ; http_response_code ( 500 ) ; echo $ exception -> getMessage ( ) ; if ( self :: $ devEnv ) echo "\n\nStack trace:\n" . $ exception -> getTraceAsString ( ) ; } return null ; }
Outputs the error popup, or a plain message, depending on the response content type.

@param \Exception|\Error      $exception Note: can't be type hinted, for PHP7 compat.
@param ResponseInterface|null $response  If null, it outputs directly to the client. Otherwise, it assumes the
object is a new blank response.
@return ResponseInterface|null
Outputs the error popup or a plain message depending on the response content type .