Skip to content

[Validator] Add shortcut to create a new ConstraintViolationList with one Constraint #41111

@lyrixx

Description

@lyrixx

Description
It's very common to do that in Symfony Application:

$violations = new ConstraintViolationList();
$violations->add(new ConstraintViolation('A publish is already running.', '', [], null, '', null));

// use ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException;
throw new ValidationException($violations);

Note: The last line is not related, but will help to better undertand

As you can see, it's a bit boring and really not straightforward to create this piece of code E_TOO_MANY_PARAMETER

What do you thing about something like:

$violations = ConstraintViolationList::createSingleConstraint('A publish is already running.');

throw new ValidationException($violations);

If it's OK for you, I'll do the PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions