Download the PHP package riper/exception-transformer without Composer
On this page you can find all versions of the php package riper/exception-transformer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download riper/exception-transformer
More information about riper/exception-transformer
Files in riper/exception-transformer
Package exception-transformer
Short Description Bundle to transform exception before the kernel catch them
License CC-BY-4.0
Homepage https://github.com/RiperFr/ExceptionTransformerBundle
Informations about the package exception-transformer
Exception transformer
This bundle can listen to exception that reach the kernel of Symfony to transform them before the kernel render them. This is useful when you want to transform domain/business exception from your code to presentation exception such as http exception that contain http status code.
Usage
Require the dependency in your composer.json
For symfony >=4 and php >=7.4
"riper/exception-transformer" : "2.*"
For symfony <4 and php <7.4
"riper/exception-transformer" : "1.*"
Register the bundle in app-kernel
new Riper\Bundle\ExceptionTransformerBundle\RiperCommonExceptionTransformerBundle(),
Transform exception with a service (most portable way)
Implement the interface \Riper\Bundle\ExceptionTransformerBundle\ExceptionTransformer\ExceptionTransformerInterface
Implement the transform method. It can (if required) throw a new exception according to the exception given.
Example : ` Create a service description tagged with the following information
- name : riper.exception.transformer
- scope: [The namespace the transformer will be restricted to]
example :
Use the built-in transformer for http error exception
You can transform your exceptions in httpException from symfony/http-kernel just by adding some configuration. No code needed.
- Create a configuration key in parameters with a unique name ending by "riper_exception_map".
- The parameter contain a key=>value with
- key = THe full namespace of the exception to transform (without a slash at the beginning)
- value = The http status to generate (an exception will be thrown with the proper http status code)
The list of available status is located in riper_exception_mapping.shortcuts parameter in __ExceptionTransformerBundle/Resources/config/exceptions_mapping.yml__. The following is a non-exhaustive list
- BadRequestHttpException
- NotFoundHttpException
- ConflictHttpException
- AccessDeniedHttpException
- GoneHttpException
- LengthRequiredHttpException
- MethodNotAllowedHttpException
- NotAcceptableHttpException
- PreconditionFailedHttpException
- PreconditionRequiredHttpException
- UnprocessableEntityHttpException
- UnsupportedMediaTypeHttpException
Example :
parameters:
customercare.contact.riper_exception_map:
Riper\Bundle\CustomerCare\ContactBundle\Exceptions\InvalidParameterException: BadRequestHttpException
Riper\Bundle\CustomerCare\ContactBundle\Exceptions\ContactException: BadRequestHttpException
The status code/exception is not in the shortcut list ? use the first method with the transformer tagged