Skip to content

[Validator] Insufficient documentation or bugs #10992

Closed
@crtl

Description

@crtl

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:

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions