PHP code example of hradigital / php-exceptions-laravel
1. Go to this page and download the library: Download hradigital/php-exceptions-laravel 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/ */
hradigital / php-exceptions-laravel example snippets
use HraDigital\Components\ExceptionRenderer\ExceptionRenderer;
use HraDigital\Components\ExceptionRenderer\Renderers\ExceptionRendererInterface;
use HraDigital\Components\Exceptions\AbstractBaseException;
use Symfony\Component\HttpFoundation\JsonResponse;
final class TenantQuotaRenderer implements ExceptionRendererInterface
{
public function supports(AbstractBaseException $exception): bool
{
return $exception instanceof \App\Exceptions\TenantQuotaExceeded;
}
public function renderAsJson(AbstractBaseException $exception): JsonResponse
{
return new JsonResponse([
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'tenant' => $exception->getData()['tenant'] ?? null,
], $exception->getCode());
}
}
// In a service provider's boot():
app(ExceptionRenderer::class)->add(new TenantQuotaRenderer());
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.