本文整理匯總了PHP中Symfony\Component\Validator\Context\ExecutionContextInterface::isConstraintValidated方法的典型用法代碼示例。如果您正苦於以下問題:PHP ExecutionContextInterface::isConstraintValidated方法的具體用法?PHP ExecutionContextInterface::isConstraintValidated怎麽用?PHP ExecutionContextInterface::isConstraintValidated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Validator\Context\ExecutionContextInterface
的用法示例。
在下文中一共展示了ExecutionContextInterface::isConstraintValidated方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateConstraints
/**
* Validates a node's value against all constraints in the given group.
*
* @param mixed $value
* The validated value.
* @param string $cache_key
* The cache key used internally to ensure we don't validate the same
* constraint twice.
* @param \Symfony\Component\Validator\Constraint[] $constraints
* The constraints which should be ensured for the given value.
*/
protected function validateConstraints($value, $cache_key, $constraints)
{
foreach ($constraints as $constraint) {
// Prevent duplicate validation of constraints, in the case
// that constraints belong to multiple validated groups
if (isset($cache_key)) {
$constraint_hash = spl_object_hash($constraint);
if ($this->context->isConstraintValidated($cache_key, $constraint_hash)) {
continue;
}
$this->context->markConstraintAsValidated($cache_key, $constraint_hash);
}
$this->context->setConstraint($constraint);
$validator = $this->constraintValidatorFactory->getInstance($constraint);
$validator->initialize($this->context);
$validator->validate($value, $constraint);
}
}
示例2: validateInGroup
/**
* Validates a node's value against all constraints in the given group.
*
* @param mixed $value The validated value
* @param string $cacheKey The key for caching the
* validated value
* @param MetadataInterface $metadata The metadata of the value
* @param string $group The group to validate
* @param ExecutionContextInterface $context The execution context
*/
private function validateInGroup($value, $cacheKey, MetadataInterface $metadata, $group, ExecutionContextInterface $context)
{
$context->setGroup($group);
foreach ($metadata->findConstraints($group) as $constraint) {
// Prevent duplicate validation of constraints, in the case
// that constraints belong to multiple validated groups
if (null !== $cacheKey) {
$constraintHash = spl_object_hash($constraint);
if ($context->isConstraintValidated($cacheKey, $constraintHash)) {
continue;
}
$context->markConstraintAsValidated($cacheKey, $constraintHash);
}
$context->setConstraint($constraint);
$validator = $this->validatorFactory->getInstance($constraint);
$validator->initialize($context);
$validator->validate($value, $constraint);
}
}