rogerthomas84/slim-http-abstracts

HTTP and middleware helpers for Slim Framework 4.0

Maintainers

Package info

github.com/rogerthomas84/slim-http-abstracts

pkg:composer/rogerthomas84/slim-http-abstracts

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.6 2022-02-04 14:38 UTC

This package is auto-updated.

Last update: 2026-03-04 23:36:32 UTC


README

Using the AppHtmlErrorRenderer

Depending on your error settings, the AppHtmlErrorRenderer can show different levels of error pages.

The only real difference is the ability to change the title of the page from Slim Application to a custom name.

<?php
// set up slim:
$app = AppFactory::create();
$app->addRoutingMiddleware();

// ...
// ...

$errorMiddleware = $app->addErrorMiddleware(
    true, // Display errors or false to hide them
    true, // Log errors
    true // Log error details
);


$errorHandler = function (
    ServerRequestInterface $request,
    Throwable $e,
    bool $displayErrorDetails,
    bool $logErrors,
    bool $logErrorDetails,
    $logger = null
) use ($app) {
    $renderer = new \SlimHttpAbstracts\Error\Renderers\AppHtmlErrorRenderer();
    $renderer->setDefaultErrorTitle('My Application Name');

    $body = $renderer->__invoke($e, $displayErrorDetails);
    $response = $app->getResponseFactory()->createResponse();
    $response->getBody()->write(
        $body
    );
    return $response;
};
$errorMiddleware->setDefaultErrorHandler($errorHandler);