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


PHP ValidatorInterface::validate方法代码示例

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


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

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

示例2: validate

 /**
  * @param SourceInterface $source
  *
  * @throws ValidationException
  */
 protected function validate(SourceInterface $source)
 {
     $violations = $this->validator->validate($source);
     if ($violations->count()) {
         throw ValidationException::create($violations);
     }
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:12,代码来源:DoctrineHandler.php

示例3: execute

 /**
  * @param CommandInterface $command
  * @return bool
  */
 public function execute(CommandInterface $command)
 {
     if (!$command instanceof EditMemberCommand) {
         throw new \DomainException("Internal error, silahkan hubungi CS kami");
     }
     $command->setRepository($this->member_repo);
     $violation = $this->validator->validate($command);
     if ($violation->count() > 0) {
         $message = $violation->get(0)->getMessage();
         throw new \DomainException($message);
     }
     //        $member = new Member();
     $member = $this->app->em->getRepository("Mabes\\Entity\\Member")->find($command->getAccountId());
     $member->setEmail($command->getEmail());
     $member->setAccountNumber($command->getAccountNumber());
     $member->setAccountHolder($command->getAccountHolder());
     $member->setBankName($command->getBankName());
     $member->setFullName($command->getFullname());
     $member->setAddress($command->getAddress());
     $member->setPhone($command->getPhone());
     $this->app->em->flush();
     //        $this->member_repo->save($member);
     $data = ["account_id" => $member->getAccountId(), "email" => $member->getEmail(), "phone" => $member->getPhone(), "fullname" => $member->getFullName(), "bank_name" => $member->getBankName(), "account_number" => $member->getAccountNumber(), "account_holder" => $member->getAccountHolder(), "address" => $member->getAddress(), "date" => date("Y-m-d H:i:s")];
     $this->event_emitter->emit("validation.created", [$data]);
     return true;
 }
开发者ID:semplon,项目名称:mabes,代码行数:30,代码来源:EditMemberService.php

示例4: validateUser

 /**
  * @param User $user
  * @throws CreateUserException
  */
 private function validateUser(User $user)
 {
     $violations = $this->validator->validate($user);
     if ($violations->count()) {
         throw new CreateUserException($violations, 'Invalid User entity.');
     }
 }
开发者ID:Nakard,项目名称:hexagonal_phonebook,代码行数:11,代码来源:CreateUser.php

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

示例6: tryValidate

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

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

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

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

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

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

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

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

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

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


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