PHP code example of httpsoft / http-error-handler

1. Go to this page and download the library: Download httpsoft/http-error-handler 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/ */

    

httpsoft / http-error-handler example snippets


use HttpSoft\ErrorHandler\ErrorHandler;

/**
 * @var Psr\Http\Message\ServerRequestInterface $request
 * @var Psr\Http\Server\RequestHandlerInterface $handler
 *
 * @var HttpSoft\ErrorHandler\ErrorListenerInterface $logErrorListener
 * @var HttpSoft\ErrorHandler\ErrorListenerInterface $sendErrorListener
 * @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator
 */

$errorHandler = new ErrorHandler($handler, $responseGenerator);

$errorHandler->addListener($logErrorListener);
$errorHandler->addListener($sendErrorListener);

/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $errorHandler->handle($request);

use HttpSoft\ErrorHandler\ErrorHandlerMiddleware;

/**
 * @var Psr\Http\Message\ServerRequestInterface $request
 * @var Psr\Http\Server\RequestHandlerInterface $handler
 *
 * @var HttpSoft\ErrorHandler\ErrorListenerInterface $logErrorListener
 * @var HttpSoft\ErrorHandler\ErrorListenerInterface $sendErrorListener
 * @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator
 */

$errorHandler = new ErrorHandlerMiddleware($responseGenerator);

$errorHandler->addListener($logErrorListener);
$errorHandler->addListener($sendErrorListener);

/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $errorHandler->process($request, $handler);