Closed
Description
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,
);