本文整理汇总了PHP中Symfony\Component\Validator\Context\ExecutionContextInterface::getValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContextInterface::getValidator方法的具体用法?PHP ExecutionContextInterface::getValidator怎么用?PHP ExecutionContextInterface::getValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Context\ExecutionContextInterface
的用法示例。
在下文中一共展示了ExecutionContextInterface::getValidator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* @param \Symfony\Component\Validator\Constraint $constraint
*/
protected function validate(Constraint $constraint)
{
$subPath = (string) $this->getCurrentPropertyPath();
if ($this->context instanceof LegacyExecutionContextInterface) {
$this->context->validateValue($this->getValue(), $constraint, $subPath, $this->group);
} else {
$this->context->getValidator()->inContext($this->context)->atPath($subPath)->validate($this->getValue(), $constraint, array($this->group));
}
}
示例2: checkEmailList
public function checkEmailList($value, ExecutionContextInterface $context)
{
$list = preg_split('/[,;]/', $value);
$emailValidator = new Constraints\Email();
foreach ($list as $email) {
$email = trim($email);
$context->getValidator()->validate($email, $emailValidator);
}
}
示例3: function
function it_does_not_validate_false_condition($constraint, NewContext $context, ValidatorInterface $validator, ContextualValidatorInterface $contextValidator)
{
$constraint->condition = function () {
return false;
};
$context->getObject()->shouldBeCalled();
$context->getValidator()->shouldNotBeCalled();
$context->validateValue(Argument::any(), Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled();
$this->initialize($context);
$this->validate('some value', $constraint);
}
示例4: expectValidateValueAt
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null)
{
switch ($this->getApiVersion()) {
case Validation::API_VERSION_2_4:
$this->context->expects($this->at($i))->method('validateValue')->with($value, $constraints, $propertyPath, $group);
break;
case Validation::API_VERSION_2_5:
case Validation::API_VERSION_2_5_BC:
$contextualValidator = $this->context->getValidator()->inContext($this->context);
$contextualValidator->expects($this->at(2 * $i))->method('atPath')->with($propertyPath)->will($this->returnValue($contextualValidator));
$contextualValidator->expects($this->at(2 * $i + 1))->method('validate')->with($value, $constraints, $group);
break;
}
}
示例5:
function it_checks_if_attribute_value_is_valid(AttributeInterface $attribute, AttributeValueInterface $attributeValue, ConstraintViolationBuilderInterface $constraintViolationBuilder, ConstraintViolationInterface $constraintViolation, ConstraintViolationListInterface $constraintViolationList, ExecutionContextInterface $context, ValidatorInterface $validator)
{
$attributeValue->getAttribute()->willReturn($attribute);
$attributeValue->getValue()->willReturn('X');
$context->getValidator()->willReturn($validator);
$validator->validate('X', Argument::type(Length::class))->willReturn($constraintViolationList);
$constraintViolationList->rewind()->shouldBeCalled();
$constraintViolationList->valid()->willReturn(true, false);
$constraintViolationList->current()->willReturn($constraintViolation);
$constraintViolationList->next()->shouldBeCalled();
$constraintViolation->getMessage()->willReturn('error message');
$context->buildViolation('error message')->willReturn($constraintViolationBuilder);
$constraintViolationBuilder->atPath('value')->willReturn($constraintViolationBuilder);
$constraintViolationBuilder->addViolation()->shouldBeCalled();
$this->validate($attributeValue, $context, ['min' => 2, 'max' => 255]);
}
示例6: expectValidateValueAt
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null)
{
$contextualValidator = $this->context->getValidator()->inContext($this->context);
$contextualValidator->expects($this->at(2 * $i))->method('atPath')->with($propertyPath)->will($this->returnValue($contextualValidator));
$contextualValidator->expects($this->at(2 * $i + 1))->method('validate')->with($value, $constraints, $group);
}
示例7: getValidationErrors
/**
* @param ExecutionContextInterface $context
* @param string $value
* @param array $validationConfiguration
*
* @return ConstraintViolationListInterface
*/
private function getValidationErrors(ExecutionContextInterface $context, $value, array $validationConfiguration)
{
$validator = $context->getValidator();
return $validator->validate($value, new Length(['min' => $validationConfiguration['min'], 'max' => $validationConfiguration['max']]));
}
示例8: getValidationErrors
/**
* {@inheritdoc}
*/
private function getValidationErrors(ExecutionContextInterface $context, $value, array $validationConfiguration)
{
$validator = $context->getValidator();
return $validator->validate($value, new GreaterThan(new \DateTime()));
}
示例9: validateRules
/**
* @param ExecutionContextInterface $context
* @param AttributeInterface $attribute
* @param DataInterface $data
*
* @throws Exception
*/
protected function validateRules(ExecutionContextInterface $context, AttributeInterface $attribute, DataInterface $data)
{
if ($attribute->isMultiple()) {
$valueData = $data->getValuesData($attribute);
} else {
$valueData = $data->getValueData($attribute);
}
$loader = new BaseLoader();
foreach ($attribute->getValidationRules() as $validationRule) {
foreach ($validationRule as $item => $options) {
$constraint = $loader->newConstraint($item, $options);
$violations = $context->getValidator()->validate($valueData, $constraint, $context->getGroup());
/** @var ConstraintViolationInterface $violation */
foreach ($violations as $violation) {
/** @noinspection DisconnectedForeachInstructionInspection */
$path = $attribute->getCode();
if ($attribute->getType()->isEmbedded()) {
if (!$attribute->isMultiple()) {
$path .= '.';
}
$path .= $violation->getPropertyPath();
}
if ($violation->getMessage()) {
$context->buildViolation($violation->getMessage())->atPath($path)->setInvalidValue($valueData)->addViolation();
} else {
$this->buildAttributeViolation($context, $attribute, strtolower($item), $valueData, $path);
}
}
}
}
}