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


PHP ExecutionContextInterface::markGroupAsValidated方法代码示例

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


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

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

示例2: validateClassNode

 /**
  * Validates a class node.
  *
  * A class node is a combination of an object with a {@link ClassMetadataInterface}
  * instance. Each class node (conceptionally) has zero or more succeeding
  * property nodes:
  *
  *     (Article:class node)
  *                \
  *        ($title:property node)
  *
  * This method validates the passed objects against all constraints defined
  * at class level. It furthermore triggers the validation of each of the
  * class' properties against the constraints for that property.
  *
  * If the selected traversal strategy allows traversal, the object is
  * iterated and each nested object is validated against its own constraints.
  * The object is not traversed if traversal is disabled in the class
  * metadata.
  *
  * If the passed groups contain the group "Default", the validator will
  * check whether the "Default" group has been replaced by a group sequence
  * in the class metadata. If this is the case, the group sequence is
  * validated instead.
  *
  * @param object                    $object            The validated object
  * @param string                    $cacheKey          The key for caching
  *                                                     the validated object
  * @param ClassMetadataInterface    $metadata          The class metadata of
  *                                                     the object
  * @param string                    $propertyPath      The property path leading
  *                                                     to the object
  * @param string[]                  $groups            The groups in which the
  *                                                     object should be validated
  * @param string[]|null             $cascadedGroups    The groups in which
  *                                                     cascaded objects should
  *                                                     be validated
  * @param int                       $traversalStrategy The strategy used for
  *                                                     traversing the object
  * @param ExecutionContextInterface $context           The current execution context
  *
  * @throws UnsupportedMetadataException  If a property metadata does not
  *                                       implement {@link PropertyMetadataInterface}
  * @throws ConstraintDefinitionException If traversal was enabled but the
  *                                       object does not implement
  *                                       {@link \Traversable}
  *
  * @see TraversalStrategy
  */
 private function validateClassNode($object, $cacheKey, ClassMetadataInterface $metadata = null, $propertyPath, array $groups, $cascadedGroups, $traversalStrategy, ExecutionContextInterface $context)
 {
     $context->setNode($object, $object, $metadata, $propertyPath);
     if (!$context->isObjectInitialized($cacheKey)) {
         foreach ($this->objectInitializers as $initializer) {
             $initializer->initialize($object);
         }
         $context->markObjectAsInitialized($cacheKey);
     }
     foreach ($groups as $key => $group) {
         // If the "Default" group is replaced by a group sequence, remember
         // to cascade the "Default" group when traversing the group
         // sequence
         $defaultOverridden = false;
         // Use the object hash for group sequences
         $groupHash = is_object($group) ? spl_object_hash($group) : $group;
         if ($context->isGroupValidated($cacheKey, $groupHash)) {
             // Skip this group when validating the properties and when
             // traversing the object
             unset($groups[$key]);
             continue;
         }
         $context->markGroupAsValidated($cacheKey, $groupHash);
         // Replace the "Default" group by the group sequence defined
         // for the class, if applicable.
         // This is done after checking the cache, so that
         // spl_object_hash() isn't called for this sequence and
         // "Default" is used instead in the cache. This is useful
         // if the getters below return different group sequences in
         // every call.
         if (Constraint::DEFAULT_GROUP === $group) {
             if ($metadata->hasGroupSequence()) {
                 // The group sequence is statically defined for the class
                 $group = $metadata->getGroupSequence();
                 $defaultOverridden = true;
             } elseif ($metadata->isGroupSequenceProvider()) {
                 // The group sequence is dynamically obtained from the validated
                 // object
                 /** @var \Symfony\Component\Validator\GroupSequenceProviderInterface $object */
                 $group = $object->getGroupSequence();
                 $defaultOverridden = true;
                 if (!$group instanceof GroupSequence) {
                     $group = new GroupSequence($group);
                 }
             }
         }
         // If the groups (=[<G1,G2>,G3,G4]) contain a group sequence
         // (=<G1,G2>), then call validateClassNode() with each entry of the
         // group sequence and abort if necessary (G1, G2)
         if ($group instanceof GroupSequence) {
             $this->stepThroughGroupSequence($object, $object, $cacheKey, $metadata, $propertyPath, $traversalStrategy, $group, $defaultOverridden ? Constraint::DEFAULT_GROUP : null, $context);
//.........这里部分代码省略.........
开发者ID:brennantom,项目名称:hackazon,代码行数:101,代码来源:RecursiveContextualValidator.php


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