我想使用 symfony2 验证器组件对字符串进行简单验证。(这需要在 symfony 2.0 中)
$responseEmail = 'somestring';
$validator = new Validator(
new ClassMetadataFactory(new StaticMethodLoader()),
new ConstraintValidatorFactory()
);
$constraint = new Assert\Collection(array(
'responseEmail' => new Assert\Collection(array(
new Assert\Email(),
new Assert\NotNull(),
)),
));
$violations = $validator->validateValue(array('responseEmail' => $responseEmail), $constraint);
这给了我一个错误:
Expected argument of type array or Traversable and ArrayAccess, string given
有谁知道为什么?