Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | >= 2.7 |
This is a minor bug in Symfony\Component\Validator\Constraints\Composite
in the Exception handling. While going through the nested constraints, a constraint that doesn't implement Symfony\Component\Validator\Constraint
results in an exception:
foreach ($nestedConstraints as $constraint) {
if (!$constraint instanceof Constraint) {
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
}
The wrong constraint will be added to the Exception message, but it is handled like a string
and not an object.
Why is this an issue?
First, we expect objects to be used in a composite instead of scalars. Using the Symfony Framework, an abstraction in form of configuration files or annotations are common, that helps us to create the constraints for the validator, which is why a wrongly created custom constrain class and validator class is a more possible occurance.
What is the expected fix?
After the instance check, the case that $constraint
can also be an object should be ensured and the class name be used in the Exception message.
I'll provide an PR for this soon.