PHP code example of cleatsquad / php-error-boundary
1. Go to this page and download the library: Download cleatsquad/php-error-boundary 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/ */
cleatsquad / php-error-boundary example snippets
use CleatSquad\ErrorBoundary\ErrorBoundary;
ErrorBoundary::install();
use CleatSquad\ErrorBoundary\ErrorResponseMapperInterface;
final class MyMapper implements ErrorResponseMapperInterface
{
public function map(array $error): array
{
// $error = ['type' => int, 'message' => string, 'file'?: string, 'line'?: int]
return [500, ['error' => ['code' => 'internal_error', 'message' => 'Something went wrong.']]];
}
}
ErrorBoundary::install(new MyMapper());
ErrorBoundary::install(null, $psr3Logger);
ErrorBoundary::uninstall();
ErrorBoundary::setShutdownInterception(function (array $error): bool {
// Return true to skip the standard JSON emit — you already answered.
return false;
});
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.