PHP code example of letkode / http-exception-bundle
1. Go to this page and download the library: Download letkode/http-exception-bundle 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/ */
use Letkode\HttpExceptionBundle\Exception\EntityNotFoundException;
throw new EntityNotFoundException('User not found.');
throw new EntityNotFoundException('User not found.', 'USER_NOT_FOUND'); // custom errorCode
use Letkode\HttpExceptionBundle\Exception\BadRequestException;
use Letkode\HttpExceptionBundle\Option\TranslationOption;
throw new BadRequestException(
'errors.invalid_range',
options: [new TranslationOption(domain: 'exceptions', parameters: ['%max%' => 10])],
);
use Letkode\HttpExceptionBundle\Exception\EntityNotFoundException;
class UserNotFoundException extends EntityNotFoundException
{
protected function defaultErrorCode(): string
{
return 'USER_NOT_FOUND';
}
}
use Letkode\HttpExceptionBundle\Exception\UnprocessableEntityException;
use Letkode\HttpExceptionBundle\Option\ErrorsOption;
throw new UnprocessableEntityException(
'Invalid input.',
'INVALID_INPUT',
options: [new ErrorsOption(['name' => ['Required.'], 'items[0].sku' => [new MyTranslatableMessage()]])],
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.