本文整理汇总了PHP中Symfony\Component\Validator\Validator\ValidatorInterface::validateValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ValidatorInterface::validateValue方法的具体用法?PHP ValidatorInterface::validateValue怎么用?PHP ValidatorInterface::validateValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Validator\ValidatorInterface
的用法示例。
在下文中一共展示了ValidatorInterface::validateValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateValue
/**
* @param mixed $value
* @param string $viewValue
* @param Constraint[]|Constraint $constraints
* @param string $subPath
* @param ValuesBag $valuesBag
* @param string[] $validationGroups
*/
private function validateValue($value, $viewValue, $constraints, $subPath, ValuesBag $valuesBag, $validationGroups = null)
{
if ($this->validator instanceof LegacyValidator) {
$violations = $this->validator->validateValue($value, $constraints, $validationGroups);
} else {
$violations = $this->validator->validate($value, $constraints, $validationGroups);
}
foreach ($violations as $violation) {
$valuesBag->addError($this->createError($violation, $viewValue, $subPath));
}
}
示例2: __invoke
/**
* @param array $item
*
* @return boolean
*/
public function __invoke(array $item)
{
if (!$this->strict) {
// Only validate properties which have an constaint.
$temp = array_intersect(array_keys($item), array_keys($this->constraints));
$item = array_intersect_key($item, array_flip($temp));
}
$constraints = new Constraints\Collection($this->constraints);
$list = $this->validator->validateValue($item, $constraints);
$currentLine = $this->line++;
if (count($list) > 0) {
$this->violations[$currentLine] = $list;
if ($this->throwExceptions) {
throw new ValidationException($list, $currentLine);
}
}
return 0 === count($list);
}