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


PHP ExecutionContextInterface::getObject方法代码示例

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


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

示例1: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     /** @var EntregaNotOverlayDates $constraint */
     /** @var Entrega $value */
     $class = ClassUtils::getClass($this->context->getObject());
     $qb = $this->manager->getRepository($class)->createQueryBuilder('a');
     $qb->andWhere('a.contrato = :contrato')->andWhere(':inico < a.fechaCierre')->andWhere(':cierre > a.fechaInicio')->setParameter('contrato', $value->getContrato())->setParameter('inico', $value->getFechaInicio())->setParameter('cierre', $value->getFechaCierre());
     if ($value->getId()) {
         $qb->andWhere('a.id != :id')->setParameter('id', $value->getId());
     }
     $results = $qb->getQuery()->execute();
     if (count($results) > 0) {
         $this->context->buildViolation($constraint->message)->addViolation();
     }
 }
开发者ID:bixlabs,项目名称:concepto-sises,代码行数:18,代码来源:EntregaNotOverlayDatesValidator.php

示例2: 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

示例3: validateNode

 /**
  * Validates a Typed Data node in the validation tree.
  *
  * If no constraints are passed, the data is validated against the
  * constraints specified in its data definition. If the data is complex or a
  * list and no constraints are passed, the contained properties or list items
  * are validated recursively.
  *
  * @param \Drupal\Core\TypedData\TypedDataInterface $data
  *   The data to validated.
  * @param \Symfony\Component\Validator\Constraint[]|null $constraints
  *   (optional) If set, an array of constraints to validate.
  * @param bool $is_root_call
  *   (optional) Whether its the most upper call in the type data tree.
  *
  * @return $this
  */
 protected function validateNode(TypedDataInterface $data, $constraints = NULL, $is_root_call = FALSE)
 {
     $previous_value = $this->context->getValue();
     $previous_object = $this->context->getObject();
     $previous_metadata = $this->context->getMetadata();
     $previous_path = $this->context->getPropertyPath();
     $metadata = $this->metadataFactory->getMetadataFor($data);
     $cache_key = spl_object_hash($data);
     $property_path = $is_root_call ? '' : PropertyPath::append($previous_path, $data->getName());
     // Pass the canonical representation of the data as validated value to
     // constraint validators, such that they do not have to care about Typed
     // Data.
     $value = $this->typedDataManager->getCanonicalRepresentation($data);
     $this->context->setNode($value, $data, $metadata, $property_path);
     if (isset($constraints) || !$this->context->isGroupValidated($cache_key, Constraint::DEFAULT_GROUP)) {
         if (!isset($constraints)) {
             $this->context->markGroupAsValidated($cache_key, Constraint::DEFAULT_GROUP);
             $constraints = $metadata->findConstraints(Constraint::DEFAULT_GROUP);
         }
         $this->validateConstraints($value, $cache_key, $constraints);
     }
     // If the data is a list or complex data, validate the contained list items
     // or properties. However, do not recurse if the data is empty.
     if (($data instanceof ListInterface || $data instanceof ComplexDataInterface) && !$data->isEmpty()) {
         foreach ($data as $name => $property) {
             $this->validateNode($property);
         }
     }
     $this->context->setNode($previous_value, $previous_object, $previous_metadata, $previous_path);
     return $this;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:48,代码来源:RecursiveContextualValidator.php

示例4: 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


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