Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug symfony#11014 [Validator] Remove property and method targets from…
… the optional and required constraints (jakzal) This PR was merged into the 2.3 branch. Discussion ---------- [Validator] Remove property and method targets from the optional and required constraints | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#11013 | License | MIT | Doc PR | At the moment both constraints can only be defined on other annotations. Both constraints are [only mentioned in the docs in the context of the Collection](http://symfony.com/doc/current/reference/constraints/Collection.html#required-and-optional-field-constraints). Defining the required or optional annotation directly on a field or method throws a ClassNotFoundException, since the constraint validator factory tries to load the validator (which does not exist): ``` ClassNotFoundException: Attempted to load class "OptionalValidator" from namespace "Symfony\Component\Validator\Constraints" in /var/www/server/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php line 71. Do you need to "use" it from another namespace? ``` By applying this patch the end user will get a more helpful error message: ``` [Semantical Error] Annotation @Assert\Optional is not allowed to be declared on property Acme\DemoBundle\Entity\Contact::$message. You may only use this annotation on these code elements: ANNOTATION. ``` Commits ------- 9c2616e [Validator] Remove property and method targets from the optional and required constraints.
- Loading branch information