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


PHP Validator\ValidatorInterface类代码示例

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


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

示例1:

 function it_does_not_validate_method_with_no_constraints(MethodInterface $method, ValidatorInterface $validator)
 {
     $constraints = [];
     $method->getValidationConstraints()->shouldBeCalled()->willReturn($constraints);
     $validator->validate([], $constraints)->shouldNotBeCalled();
     $this->validate($method);
 }
开发者ID:web3d,项目名称:mincart,代码行数:7,代码来源:ValidatorSpec.php

示例2: apply

 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $snakeCasedName = $this->camelCaseToSnakeCase($name);
     $class = $configuration->getClass();
     $json = $request->getContent();
     $object = json_decode($json, true);
     if (!isset($object[$snakeCasedName]) || !is_array($object[$snakeCasedName])) {
         throw new BadJsonRequestException([sprintf("Missing parameter '%s'", $name)]);
     }
     $object = $object[$snakeCasedName];
     $convertedObject = new $class();
     $errors = [];
     foreach ($object as $key => $value) {
         $properlyCasedKey = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key))));
         if (!property_exists($convertedObject, $properlyCasedKey)) {
             $errors[] = sprintf("Unknown property '%s.%s'", $snakeCasedName, $key);
             continue;
         }
         $convertedObject->{$properlyCasedKey} = $value;
     }
     $violations = $this->validator->validate($convertedObject);
     if (count($errors) + count($violations) > 0) {
         throw BadJsonRequestException::createForViolationsAndErrors($violations, $name, $errors);
     }
     $request->attributes->set($name, $convertedObject);
 }
开发者ID:surfnet,项目名称:stepup-bundle,代码行数:27,代码来源:JsonConvertibleParamConverter.php

示例3: testExecuteWithoutViolations

 public function testExecuteWithoutViolations()
 {
     $list = new ConstraintViolationList([]);
     $this->validator->shouldReceive('validate')->once()->andReturn($list);
     $this->middleware->execute(new FakeCommand(), function () {
     });
 }
开发者ID:nejcpenko,项目名称:tactician-bundle,代码行数:7,代码来源:ValidatorMiddlewareTest.php

示例4: validateCommand

 /**
  * @param mixed $command
  *
  * @return array
  */
 private function validateCommand($command)
 {
     if ($this->validator) {
         return $this->validator->validate($command);
     }
     return null;
 }
开发者ID:simgroep,项目名称:event-sourcing,代码行数:12,代码来源:CommandFactory.php

示例5: validate

 /**
  * 
  * @param object $object
  * @throws ValidationException
  */
 public function validate($object)
 {
     $violations = $this->validator->validate($object);
     if (count($violations) > 0) {
         throw new ValidationException($violations);
     }
 }
开发者ID:johnarben2468,项目名称:sampleffuf-core,代码行数:12,代码来源:Validator.php

示例6: testValidationConfiguration

 public function testValidationConfiguration()
 {
     $valid = $this->validator->validate(new ProductCollection([]));
     $this->assertCount(1, $valid);
     $productCollectionWithWrongProduct = new ProductCollection([new Product()]);
     $this->assertCount(3, $this->validator->validate($productCollectionWithWrongProduct));
 }
开发者ID:krzysztof-gzocha,项目名称:payu,代码行数:7,代码来源:ProductCollectionTest.php

示例7: validate

 /**
  * @param string          $dataClass Parent entity class name
  * @param File|Attachment $entity    File entity
  * @param string          $fieldName Field name where new file/image field was added
  *
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 public function validate($dataClass, $entity, $fieldName = '')
 {
     /** @var Config $entityAttachmentConfig */
     if ($fieldName === '') {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass);
         $mimeTypes = $this->getMimeArray($entityAttachmentConfig->get('mimetypes'));
         if (!$mimeTypes) {
             $mimeTypes = array_merge($this->getMimeArray($this->config->get('oro_attachment.upload_file_mime_types')), $this->getMimeArray($this->config->get('oro_attachment.upload_image_mime_types')));
         }
     } else {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass, $fieldName);
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $entityAttachmentConfig->getId();
         if ($fieldConfigId->getFieldType() === 'file') {
             $configValue = 'upload_file_mime_types';
         } else {
             $configValue = 'upload_image_mime_types';
         }
         $mimeTypes = $this->getMimeArray($this->config->get('oro_attachment.' . $configValue));
     }
     $fileSize = $entityAttachmentConfig->get('maxsize') * 1024 * 1024;
     foreach ($mimeTypes as $id => $value) {
         $mimeTypes[$id] = trim($value);
     }
     return $this->validator->validate($entity->getFile(), [new FileConstraint(['maxSize' => $fileSize, 'mimeTypes' => $mimeTypes])]);
 }
开发者ID:ramunasd,项目名称:platform,代码行数:33,代码来源:ConfigFileValidator.php

示例8: validate

 /**
  * @param Validatable $comment
  *
  * @throws ValidationError
  * @return void
  */
 public function validate(Validatable $comment)
 {
     $errors = $this->validator->validate($comment);
     if ($errors->count()) {
         throw new ValidationError($errors);
     }
 }
开发者ID:microservices-playground,项目名称:api-comments,代码行数:13,代码来源:CreateCommentHandler.php

示例9: testCreateUserWithDisabledValidationWillProceedImmediatelyToSave

 public function testCreateUserWithDisabledValidationWillProceedImmediatelyToSave()
 {
     $user = $this->createExampleUser();
     $this->validatorMock->expects($this->never())->method('validate');
     $this->repositoryMock->expects($this->once())->method('save')->with($user);
     $this->useCase->createUser($user, false);
 }
开发者ID:Nakard,项目名称:hexagonal_phonebook,代码行数:7,代码来源:CreateUserTest.php

示例10: tryValidate

 private function tryValidate(Article $article)
 {
     $errors = $this->validator->validate($article);
     if (count($errors)) {
         throw new \Exception(implode('\\n', $errors));
     }
 }
开发者ID:pinekta,项目名称:mysymfonysample,代码行数:7,代码来源:ArticleManager.php

示例11: validate

 /**
  * @inheritdoc
  */
 public function validate($value, Param $param)
 {
     $constraint = $this->getRequirementsConstraint($value, $param);
     if (null !== $constraint) {
         $constraint = [$constraint];
         if ($param->allowBlank === false) {
             $constraint[] = new NotBlank();
         }
         if ($param->nullable === false) {
             $constraint[] = new NotNull();
         }
     } else {
         $constraint = [];
     }
     if ($param->array) {
         $constraint = [new All(['constraints' => $constraint])];
     }
     if ($param->incompatibles) {
         $constraint[] = new IncompatibleParams($param->incompatibles);
     }
     if (!count($constraint)) {
         return new ConstraintViolationList();
     }
     return $this->validator->validate($value, $constraint);
 }
开发者ID:alekitto,项目名称:param-fetcher-bundle,代码行数:28,代码来源:ParamValidator.php

示例12: validate

 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof OrderInterface) {
         $this->context->buildViolation('Value should implements OrderInterface')->addViolation();
     }
     if ($value->getUser() === null) {
         $emailErrors = $this->validator->validate($value->getEmail(), [new NotNull(), new Email()]);
         foreach ($emailErrors as $error) {
             $this->context->buildViolation($error->getMessage())->addViolation();
         }
     }
     $shippingAddressErrors = $this->validator->validate($value->getShippingAddress());
     if (count($shippingAddressErrors)) {
         /** @var ConstraintViolation $error */
         foreach ($shippingAddressErrors as $error) {
             $this->context->buildViolation($error->getMessage())->addViolation();
         }
     }
     if ($value->isDifferentBillingAddress()) {
         $billingAddressErrors = $this->validator->validate($value->getBillingAddress());
         if (count($billingAddressErrors)) {
             /** @var ConstraintViolation $error */
             foreach ($billingAddressErrors as $error) {
                 $this->context->buildViolation($error->getMessage())->addViolation();
             }
         }
     }
 }
开发者ID:enhavo,项目名称:enhavo,代码行数:28,代码来源:OrderAddressingValidator.php

示例13: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (empty($options['data_class'])) {
         return;
     }
     $className = $options['data_class'];
     if (!$this->doctrineHelper->isManageableEntity($className)) {
         return;
     }
     if (!$this->entityConfigProvider->hasConfig($className)) {
         return;
     }
     $uniqueKeys = $this->entityConfigProvider->getConfig($className)->get('unique_key');
     if (empty($uniqueKeys)) {
         return;
     }
     /* @var \Symfony\Component\Validator\Mapping\ClassMetadata $validatorMetadata */
     $validatorMetadata = $this->validator->getMetadataFor($className);
     foreach ($uniqueKeys['keys'] as $uniqueKey) {
         $fields = $uniqueKey['key'];
         $labels = array_map(function ($fieldName) use($className) {
             $label = $this->entityConfigProvider->getConfig($className, $fieldName)->get('label');
             return $this->translator->trans($label);
         }, $fields);
         $constraint = new UniqueEntity(['fields' => $fields, 'errorPath' => '', 'message' => $this->translator->transChoice('oro.entity.validation.unique_field', sizeof($fields), ['%field%' => implode(', ', $labels)])]);
         $validatorMetadata->addConstraint($constraint);
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:31,代码来源:UniqueEntityExtension.php

示例14: process

 /**
  * {@inheritdoc}
  */
 public function process($item)
 {
     $entity = $this->findOrCreateObject($item);
     try {
         $this->updater->update($entity, $item);
     } catch (\InvalidArgumentException $exception) {
         $this->skipItemWithMessage($item, $exception->getMessage(), $exception);
     }
     $violations = $this->validator->validate($entity);
     if ($violations->count() > 0) {
         $this->objectDetacher->detach($entity);
         $this->skipItemWithConstraintViolations($item, $violations);
     }
     $rawParameters = $entity->getRawParameters();
     if (!empty($rawParameters)) {
         $job = $this->jobRegistry->get($entity->getJobName());
         $parameters = $this->jobParamsFactory->create($job, $rawParameters);
         $violations = $this->jobParamsValidator->validate($job, $parameters);
         if ($violations->count() > 0) {
             $this->objectDetacher->detach($entity);
             $this->skipItemWithConstraintViolations($item, $violations);
         }
     }
     return $entity;
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:28,代码来源:JobInstanceProcessor.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate(ServiceReference $service, array $arguments)
 {
     $validationResult = array();
     $parameterCount = 0;
     $validatedCount = 0;
     $hasStrictFailure = false;
     foreach ($arguments as $name => $value) {
         if (strpos($name, '__internal__') !== false) {
             continue;
         }
         $constraints = $service->getParameterConstraints($name);
         $validationGroups = $service->getParameterValidationGroups($name);
         $isStrictValidation = $service->isStrictParameterValidation($name);
         if (!empty($constraints)) {
             $violations = $this->validator->validate($value, $constraints, $validationGroups);
             if (count($violations)) {
                 $validationResult[$name] = $violations;
                 if ($isStrictValidation) {
                     $hasStrictFailure = true;
                 }
             }
             $validatedCount++;
         }
         $parameterCount++;
     }
     if ($this->strict && $parameterCount !== $validatedCount) {
         throw new StrictArgumentValidationException();
     }
     if (!empty($validationResult)) {
         throw new ArgumentValidationException(new ArgumentValidationResult($validationResult), $hasStrictFailure);
     }
 }
开发者ID:teqneers,项目名称:ext-direct,代码行数:35,代码来源:ArgumentValidator.php


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