Skip to content

[Validator] Document Collection constraint in combination with Optional/Required #999

Closed
@webmozart

Description

@webmozart

As of 2.1, there are two new constraints that can be used with Collection: Optional and Required. They give more flexibility over the existing options allowExtraFields and allowMissingFields.

Usage:

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\Collection\Optional;
use Symfony\Component\Validator\Constraints\Collection\Required;

/**
 * @Assert\Collection({
 *     foo = @Required(),
 *     bar = @Optional(),
 *     baz = @Required(@Assert\Min(3)),
 *     bam = @Optional({@Assert\NotNull, @Assert\MinLength(7)})
 * )}
private $options = array(
    'foo' => null,
    'baz' => 10,
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    ValidatoractionableClear and specific issues ready for anyone to take them.good first issueIdeal for your first contribution! (some Symfony experience may be required)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions