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


PHP ValidatorInterface::validateObjectByVarTags方法代码示例

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


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

示例1: resolveRequest

 /**
  * Resolve request parameter
  *
  * @param ActionInterface      $action
  * @param CallableInterface    $callable
  * @param array                $inputArguments
  * @param \ReflectionParameter $parameter
  *
  * @return object
  *
  * @throws \Exception
  */
 private function resolveRequest(ActionInterface $action, CallableInterface $callable, array $inputArguments, \ReflectionParameter $parameter)
 {
     $class = $parameter->getClass();
     if ($class->isInterface()) {
         throw new \RuntimeException(sprintf('Could not create instance via interface for parameter "%s" in method "%s". ' . 'You must set the class for type hinting.', $parameter->getName(), Reflection::getCalledMethod($callable->getReflection())));
     }
     if ($class->isAbstract()) {
         throw new \RuntimeException(sprintf('Could not create instance via abstract class for parameter "%s" in method "%s". ' . 'You must set the real class for type hinting.', $parameter->getName(), Reflection::getCalledMethod($callable->getReflection())));
     }
     /** @var RequestInterface $request */
     $request = $class->newInstance();
     // Map arguments
     $this->objectMapper->map($request, $inputArguments, ObjectMetadata::DEFAULT_GROUP);
     // Validate process
     if ($this->validator) {
         if ($this->validator instanceof VarTagValidatorInterface) {
             $violationList = $this->validator->validateObjectByVarTags($request);
             if (count($violationList)) {
                 throw ViolationListException::create($violationList);
             }
         }
         $violationList = $this->validator->validate($request);
         if (count($violationList)) {
             throw ViolationListException::create($violationList);
         }
     }
     return $request;
 }
开发者ID:rockefys,项目名称:Api,代码行数:40,代码来源:ObjectMapperParameterResolverAndExtractor.php

示例2: strictRequestValidate

 /**
  * Strict request validation
  *
  * @param RequestInterface $request
  *
  * @throws ViolationListException
  */
 private function strictRequestValidate(RequestInterface $request)
 {
     $requestMetadata = $this->validator->getMetadataFor($request);
     $useStrictGroup = false;
     // Search constraints by group "Strict"
     if ($requestMetadata instanceof ClassMetadata) {
         foreach ($requestMetadata->getConstrainedProperties() as $propertyName) {
             $propertyMetadata = $requestMetadata->getPropertyMetadata($propertyName);
             if (count($propertyMetadata)) {
                 $propertyMetadata = array_shift($propertyMetadata);
             } else {
                 continue;
             }
             $constraintsInStrictGroup = $propertyMetadata->findConstraints('Strict');
             if (count($constraintsInStrictGroup)) {
                 $useStrictGroup = true;
                 break;
             }
         }
     }
     if ($useStrictGroup) {
         // The any properties in request class have a "Strict" group validation
         $violationList = $this->validator->validate($request, null, ['Strict']);
         if (count($violationList)) {
             throw ViolationListException::create($violationList);
         }
         return;
     }
     if ($this->validator instanceof VarTagValidatorInterface) {
         $violationList = $this->validator->validateObjectByVarTags($request);
         if (count($violationList)) {
             throw ViolationListException::create($violationList);
         }
     }
 }
开发者ID:Gtvar,项目名称:FivePercent-Api,代码行数:42,代码来源:ObjectMapperParameterResolverAndExtractor.php


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