Skip to content

Instantly share code, notes, and snippets.

@mdzwigala
Created December 4, 2020 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdzwigala/36a6e2a817bd24d8e2bd1931e23455ae to your computer and use it in GitHub Desktop.
Save mdzwigala/36a6e2a817bd24d8e2bd1931e23455ae to your computer and use it in GitHub Desktop.
ADR-EXAMPLE\Infrastructure\SymfonyViolationListConverter
<?php
declare(strict_types=1);
namespace App\Infrastructure\Service;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationListInterface;
final class SymfonyViolationListConverter
{
public function convertToArray(ConstraintViolationListInterface $list): array
{
$errors = [];
/** @var ConstraintViolation $violation */
foreach ($list as $violation) {
$errors[$violation->getPropertyPath()][] = $violation->getMessage();
}
return $errors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment