-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] type constraint with multi-types is not handled #31330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That be a new feature, it's documented to be a string currently: https://symfony.com/doc/current/reference/constraints/Type.html#reference-constraint-type-type |
…ypes (jschaedl) This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Improve TypeValidator to handle array of types | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31330 | License | MIT | Doc PR | tbd. The `@Type` constraint is now able to handle multiple types: ```php /** * @var string|array * @Assert\Type(type={"string", "array"}) */ private $name; ``` and will pass when `$name` is either of type `string` or `array`. Commits ------- c8100f3 [Validator] Improve TypeValidator to handle array of types
For those who are using an old validator version and cannot upgrade it, you can use For example, if you want to validate your data as
You could even have 'payload' as an array and iterate over it to apply your validations one at a time. |
Symfony version(s) affected: 4.2.1
Description
When I define a constraint type with multi-types (array of types), PHP returns a warning on line :
symfony/validator/Constraints/TypeValidator.php:36
, (strtolower()
function with an array).How to reproduce
Create an object with a property having the following type constraint :
Possible Solution
InvalidMultiTypesException
Additional context
The text was updated successfully, but these errors were encountered: