Symfony bundle which provides Unified Error Normalizer allowing to easily
normalize/denormalize ConstraintViolationList
from Symfony's Validator component.
This package is currently in the active development.
- PHP 7.2 or greater
- Symfony 4.4 or Symfony 5.x
Normalization example:
use Easir\ErrorNormalizerBundle\NameConverter\FieldNameConverter;
use Easir\ErrorNormalizerBundle\Normalizer\UnifiedConstraintViolationListNormalizer;
use Symfony\Component\Validator\ConstraintViolationList;
$normalizer = new UnifiedConstraintViolationListNormalizer(new FieldNameConverter());
/** @var Symfony\Component\Validator\Validator\ValidatorInterface $validator */
$constraintViolationList = $validator->validate($data);
$errors = $this->normalizer->normalize($data, ConstraintViolationList::class);
Normalization process will return an array in format like below:
$errors = [
'errors' => [
[
'message' => 'Error message here',
'code' => 'validation.email',
'field' => 'contact.email',
],
],
];
Note! This bundle provides Symfony's DependencyInjection service definition which means it should be possible to use Symfony's Serializer component without explicitly creating the normalizer.
This bundle is being served only from private repository therefore it is required
to add proper repository into your composer.json
file.
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/easir/error-normalizer-bundle.git"
}
]
}
Require the bundle implementation with Composer:
composer require easir/error-normalizer-bundle
Install all the needed packages required to develop the project:
composer install
Note! This bundle is developed against different versions of Symfony, please remember to run the tests with lowest dependencies. You can easily achieve that by running dependency installation with
--prefer-lowest
.
You can run the test suite using the following command:
vendor/bin/phpunit
This bundle enforces the Easir Code Standards during development using the PHP CS Fixer utility. Before committing any code, you can run the utility so it can fix any potential rule violations for you:
vendor/bin/phpcs
Use the issue tracker to report any issues you might have.
See the LICENSE file for license rights and limitations (MIT).