Description
I wanted to use the validator component but I am having some problems and many of them are related to insufficient docs.
Either im to dumb, the docs are incomplete, theres a bug or all of the three.
Given the following example:
$constraints = new Assert\Collection([
"type" => new Assert\Choice([
"choices" => ["credentials", "google"],
"groups" => ["type"]
]),
"token" => new Assert\NotBlank([
"groups" => ["google"]
])
]);
$data = ["type" => "credentials"]
$validator = Validation::createValidator();
$result = $validator->validate($data, $constraints, "type");
The Resulting messages are:
type = 'The value you selected is not a valid choice.'
token = 'The field is missing'
According to the documentation:
- How to Apply only a Subset of all Your Validation Constraints (Validation Groups)
- How to Validate Raw Values (Scalar Values and Arrays)
- How to Sequentially Apply Validation Groups
Only the group type
should be validated.
If I pass a sequence of ["type", "google"]
it validates the type
group first and then validates google
group, but shows all fields from type
group as unexpected fields.
Aside of that, all examples are given for object validation.
Usually you will be validating entire objects. But sometimes, you just want to validate a simple value[...]
Its the total opposite in my opinion, in most cases you will get input as an scalar, array or object and not a Class.