0 follower

Final Class Yiisoft\ErrorHandler\Renderer\PlainTextRenderer

InheritanceYiisoft\ErrorHandler\Renderer\PlainTextRenderer
ImplementsYiisoft\ErrorHandler\ThrowableRendererInterface

Formats throwable into plain text string.

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT_ERROR_MESSAGE 'An internal server error occurred.' Yiisoft\ErrorHandler\ThrowableRendererInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $contentType 'text/plain' )
$contentType string

                public function __construct(
    private readonly string $contentType = 'text/plain',
) {
}

            
render() public method

public Yiisoft\ErrorHandler\ErrorData render ( Throwable $t, \Psr\Http\Message\ServerRequestInterface|null $request null )
$t Throwable
$request \Psr\Http\Message\ServerRequestInterface|null

                public function render(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
{
    return new ErrorData(
        self::DEFAULT_ERROR_MESSAGE,
        [Header::CONTENT_TYPE => $this->contentType],
    );
}

            
renderVerbose() public method

public Yiisoft\ErrorHandler\ErrorData renderVerbose ( Throwable $t, \Psr\Http\Message\ServerRequestInterface|null $request null )
$t Throwable
$request \Psr\Http\Message\ServerRequestInterface|null

                public function renderVerbose(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
{
    return new ErrorData(
        self::throwableToString($t),
        [Header::CONTENT_TYPE => $this->contentType],
    );
}

            
throwableToString() public static method

public static string throwableToString ( Throwable $t )
$t Throwable

                public static function throwableToString(Throwable $t): string
{
    return sprintf(
        <<<TEXT
            %s with message "%s"
            in %s:%s
            Stack trace:
            %s
            TEXT,
        $t::class,
        $t->getMessage(),
        $t->getFile(),
        $t->getLine(),
        $t->getTraceAsString()
    );
}