PHP code example of rogerthomas84 / slim-http-abstracts

1. Go to this page and download the library: Download rogerthomas84/slim-http-abstracts library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rogerthomas84 / slim-http-abstracts example snippets



// 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);