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


PHP ExecutionContextInterface::getGroup方法代码示例

本文整理汇总了PHP中Symfony\Component\Validator\Context\ExecutionContextInterface::getGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContextInterface::getGroup方法的具体用法?PHP ExecutionContextInterface::getGroup怎么用?PHP ExecutionContextInterface::getGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Validator\Context\ExecutionContextInterface的用法示例。


在下文中一共展示了ExecutionContextInterface::getGroup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validatePropertyValue

 /**
  * {@inheritdoc}
  */
 public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null)
 {
     $classMetadata = $this->metadataFactory->getMetadataFor($objectOrClass);
     if (!$classMetadata instanceof ClassMetadataInterface) {
         // Cannot be UnsupportedMetadataException because of BC with
         // Symfony < 2.5
         throw new ValidatorException(sprintf('The metadata factory should return instances of ' . '"\\Symfony\\Component\\Validator\\Mapping\\ClassMetadataInterface", ' . 'got: "%s".', is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)));
     }
     $propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
     $groups = $groups ? $this->normalizeGroups($groups) : $this->defaultGroups;
     if (is_object($objectOrClass)) {
         $object = $objectOrClass;
         $cacheKey = spl_object_hash($objectOrClass);
         $propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName);
     } else {
         // $objectOrClass contains a class name
         $object = null;
         $cacheKey = null;
         $propertyPath = $this->defaultPropertyPath;
     }
     $previousValue = $this->context->getValue();
     $previousObject = $this->context->getObject();
     $previousMetadata = $this->context->getMetadata();
     $previousPath = $this->context->getPropertyPath();
     $previousGroup = $this->context->getGroup();
     foreach ($propertyMetadatas as $propertyMetadata) {
         $this->validateGenericNode($value, $object, $cacheKey . ':' . $propertyName, $propertyMetadata, $propertyPath, $groups, null, TraversalStrategy::IMPLICIT, $this->context);
     }
     $this->context->setNode($previousValue, $previousObject, $previousMetadata, $previousPath);
     $this->context->setGroup($previousGroup);
     return $this;
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:35,代码来源:RecursiveContextualValidator.php

示例2: __construct

 /**
  * Creates a validator for the given context.
  *
  * @param ExecutionContextInterface           $context          The execution context
  * @param MetadataFactoryInterface            $metadataFactory  The factory for
  *                                                              fetching the metadata
  *                                                              of validated objects
  * @param ConstraintValidatorFactoryInterface $validatorFactory The factory for creating
  *                                                              constraint validators
  */
 public function __construct(ExecutionContextInterface $context, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory)
 {
     $this->context = $context;
     $this->defaultPropertyPath = $context->getPropertyPath();
     $this->defaultGroups = array($context->getGroup() ?: Constraint::DEFAULT_GROUP);
     $this->metadataFactory = $metadataFactory;
     $this->validatorFactory = $validatorFactory;
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:18,代码来源:RecursiveContextualValidator.php

示例3: function

 function it_validates_object($constraint, NewContext $context, ValidatorInterface $validator, ContextualValidatorInterface $contextValidator)
 {
     $constraint->condition = function ($object) {
         return $object->name == 'some name';
     };
     $object = new \stdClass();
     $object->name = 'some name';
     $context->getGroup()->shouldBeCalled();
     $context->getObject()->willReturn($object);
     $context->getValidator()->willReturn($validator);
     $validator->inContext($context)->willReturn($contextValidator);
     $contextValidator->validate($object, $constraint->constraints, Argument::any())->shouldBeCalled();
     $this->initialize($context);
     $this->validate($object, $constraint);
 }
开发者ID:bcastellano,项目名称:symfony-validator-conditional,代码行数:15,代码来源:ConditionalValidatorSpec.php

示例4: 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::getGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。