当前位置: 首页>>代码示例>>PHP>>正文


PHP ExecutionContextInterface::getValidator方法代码示例

本文整理汇总了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));
     }
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:12,代码来源:ErrorElement.php

示例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);
     }
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:9,代码来源:ConfigStoreForm.php

示例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);
 }
开发者ID:bcastellano,项目名称:symfony-validator-conditional,代码行数:11,代码来源:ConditionalValidatorSpec.php

示例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;
     }
 }
开发者ID:alexbogo,项目名称:symfony,代码行数:14,代码来源:AbstractConstraintValidatorTest.php

示例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]);
 }
开发者ID:TheMadeleine,项目名称:Sylius,代码行数:16,代码来源:TextAttributeTypeSpec.php

示例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);
 }
开发者ID:ABaldwinHunter,项目名称:symfony-clone,代码行数:6,代码来源:AbstractConstraintValidatorTest.php

示例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']]));
 }
开发者ID:loic425,项目名称:Sylius,代码行数:12,代码来源:TextAttributeType.php

示例8: getValidationErrors

 /**
  * {@inheritdoc}
  */
 private function getValidationErrors(ExecutionContextInterface $context, $value, array $validationConfiguration)
 {
     $validator = $context->getValidator();
     return $validator->validate($value, new GreaterThan(new \DateTime()));
 }
开发者ID:next-sentence,项目名称:sylius-test,代码行数:8,代码来源:IntervalAttributeType.php

示例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);
                 }
             }
         }
     }
 }
开发者ID:VincentChalnot,项目名称:SidusEAVModelBundle,代码行数:38,代码来源:DataValidator.php


注:本文中的Symfony\Component\Validator\Context\ExecutionContextInterface::getValidator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。