PHP code example of chubbyphp / chubbyphp-error-handler
1. Go to this page and download the library: Download chubbyphp/chubbyphp-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.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chubbyphp / chubbyphp-error-handler example snippets
useChubbyphp\ErrorHandler\ErrorHandlerMiddleware;
useChubbyphp\ErrorHandler\ErrorHandlerInterface;
$middleware = new ErrorHandlerMiddleware(new <ErrorHandlerInterface>);
$middleware($request, $response, $next);
useChubbyphp\ErrorHandler\SimpleErrorHandler;
$errorHandler = new SimpleErrorHandler($provider);
$response = $errorHandler($request, $response, $exception);
useChubbyphp\ErrorHandler\SimpleErrorHandlerProvider;
useMyProject\ErrorHandler\JsonErrorResponseProvider;
usePimple/Container;
$container = new Container();
$container->register(new SimpleErrorHandlerProvider);
// IMPORTANT: without this definition, the error handler will not work!
$container['errorHandler.defaultProvider'] = function()use($container){
returnnew JsonErrorResponseProvider;
};
$app->add($container['errorHandler.middleware']);
useChubbyphp\ErrorHandler\ContentTypeResolver;
useNegotiation\Negotiator;
usePsr\Http\Message\ServerRequestInterfaceasRequest;
$resolver = new ContentTypeResolver(new Negotiator);
$resolver->getContentType($request, ['text/html']);
useChubbyphp\ErrorHandler\AdvancedErrorHandlerProvider;
useMyProject\ErrorHandler\JsonErrorResponseProvider;
useMyProject\ErrorHandler\XmlErrorResponseProvider;
usePimple/Container;
$container = new Container();
$container->register(new AdvancedErrorHandlerProvider);
// IMPORTANT: without this definition, the error handler will not work!
$container['errorHandler.defaultProvider'] = function()use($container){
returnnew JsonErrorResponseProvider;
};
// optional: add more than the default provider
$container->extend('errorHandler.providers', function(array $providers){
$providers[] = new XmlErrorResponseProvider;
return $providers;
});
$app->add($container['errorHandler.middleware']);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.