我使用Symfony 4.1并且我想要一个字段,名称的标识符,它可以接收电子邮件或一个电话号码。
所以我想要有效,如果字段是电子邮件,或者字段是电话号码。
$constraint = new Assert\Collection([
'op' => new Assert\Required([
new Assert\Choice(['choices' => Operators::toArray()]),
]),
'value' => [
new Assert\Required([
new Assert\Collection([
'identifier' => [
new Assert\Email(),
],
]),
]),
],
]);
return $this->validator->validate($data, $constraint);
我发送的身体是:
[
{
"op": "add",
"value": {
"identifier": "john.doe@example.com",
"identifierType": "email"
}
},
{
"op": "add",
"value": {
"identifier": "+33600000000",
"identifierType": "phone"
}
}
]