當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ValidatorInterface::validate方法代碼示例

本文整理匯總了PHP中Symfony\Component\Validator\ValidatorInterface::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP ValidatorInterface::validate方法的具體用法?PHP ValidatorInterface::validate怎麽用?PHP ValidatorInterface::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Validator\ValidatorInterface的用法示例。


在下文中一共展示了ValidatorInterface::validate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate

 /**
  * @param mixed $data
  * @throws MissingDependencyException
  */
 public function validate($data)
 {
     if (!$this->validator) {
         throw new MissingDependencyException('No validator present.');
     }
     return $this->validator->validate($data);
 }
開發者ID:seiffert,項目名稱:controller-helper-bundle,代碼行數:11,代碼來源:ValidatorHelper.php

示例2: run

 /**
  * Validate data
  *
  * @param EntityData $data
  * @throws ValidationException
  */
 public function run(EntityData $data)
 {
     $constraintViolations = $this->validator->validate($data);
     if ($constraintViolations->count()) {
         throw new ValidationException($constraintViolations);
     }
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:13,代碼來源:ValidateStep.php

示例3: update

 /**
  * {@inheritdoc}
  *
  * Expected input format :
  * {
  *     'attribute': 'maximum_print_size',
  *     'code': '210_x_1219_mm',
  *     'sort_order': 2,
  *     'labels': {
  *         'de_DE': '210 x 1219 mm',
  *         'en_US': '210 x 1219 mm',
  *         'fr_FR': '210 x 1219 mm'
  *     }
  * }
  *
  * @throws BusinessValidationException
  */
 public function update($attributeOption, array $data, array $options = [])
 {
     if (!$attributeOption instanceof AttributeOptionInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\AttributeOptionInterface", "%s" provided.', ClassUtils::getClass($attributeOption)));
     }
     // TODO: ugly fix to workaround issue with "attribute.group.code: This value should not be blank."
     // in case of existing option, attribute is a proxy, attribute group too, the validated group code is null
     $attributeOption->getAttribute() !== null ? $attributeOption->getAttribute()->getGroup()->getCode() : null;
     $isNew = $attributeOption->getId() === null;
     $readOnlyFields = ['attribute', 'code'];
     $updateViolations = new ConstraintViolationList();
     foreach ($data as $field => $data) {
         $isReadOnlyField = in_array($field, $readOnlyFields);
         if ($isNew || !$isReadOnlyField) {
             try {
                 $this->setData($attributeOption, $field, $data);
             } catch (\InvalidArgumentException $e) {
                 $setViolation = new ConstraintViolation($e->getMessage(), $e->getMessage(), [], $attributeOption, null, null);
                 $updateViolations->add($setViolation);
             }
         }
     }
     $validatorViolations = $this->validator->validate($attributeOption);
     $updateViolations->addAll($validatorViolations);
     if ($updateViolations->count() > 0) {
         throw new BusinessValidationException($updateViolations);
     }
     return $this;
 }
開發者ID:vpetrovych,項目名稱:pim-community-dev,代碼行數:46,代碼來源:AttributeOptionUpdater.php

示例4: validateContainer

 /**
  * @param Container $container
  * @param object $entity
  * @return \Symfony\Component\Validator\ConstraintViolationInterface[]|ConstraintViolationList
  */
 public function validateContainer(Container $container, $entity)
 {
     if ($entity === NULL) {
         return;
     }
     $meta = $this->em->getClassMetadata(get_class($entity));
     $groups = NULL;
     if ($entity instanceof GroupSequenceProviderInterface) {
         $groups = $entity->getGroupSequence();
     }
     /** @var ConstraintViolationList|ConstraintViolationInterface[] $violations */
     $violations = $this->validator->validate($entity, $groups);
     $this->mapViolationsToForm($container, $violations);
     foreach ($container->getComponents(FALSE, 'Nette\\Forms\\Container') as $child) {
         /** @var Nette\Forms\Container $child */
         if (!$meta->hasAssociation($field = $child->getName())) {
             continue;
         }
         if ($meta->isSingleValuedAssociation($field)) {
             $this->validateContainer($child, $meta->getFieldValue($entity, $field));
         } else {
             throw new NotImplementedException("To many relation is not yet implemented");
         }
     }
 }
開發者ID:kuba1999,項目名稱:DoctrineForms,代碼行數:30,代碼來源:ConstraintViolationsMapper.php

示例5: validate

 /**
  * @param SourceInterface $source
  *
  * @throws ValidationException
  */
 protected function validate(SourceInterface $source)
 {
     $violations = $this->validator->validate($source);
     if ($violations->count()) {
         throw ValidationException::create($violations);
     }
 }
開發者ID:mvanduijker,項目名稱:FMIoBundle,代碼行數:12,代碼來源:DoctrineHandler.php

示例6: process

 /**
  * {@inheritdoc}
  */
 public function process(VariableInterface $variable, VariantInterface $variant)
 {
     if (0 < count($this->validator->validate($variant, array('sylius')))) {
         $variable->removeVariant($variant);
     } else {
         $this->eventDispatcher->dispatch('sylius.variant.pre_create', new GenericEvent($variant));
     }
 }
開發者ID:aleherse,項目名稱:Sylius,代碼行數:11,代碼來源:VariantGenerator.php

示例7: add

 /**
  * Add a new enrichment to the indexer
  *
  * @param \Searchperience\Api\Client\Domain\Enrichment\Enrichment $enrichment
  * @throws \Searchperience\Common\Exception\InvalidArgumentException
  * @return integer HTTP Status code
  */
 public function add(\Searchperience\Api\Client\Domain\Enrichment\Enrichment $enrichment)
 {
     $violations = $this->enrichmentValidator->validate($enrichment);
     if ($violations->count() > 0) {
         throw new \Searchperience\Common\Exception\InvalidArgumentException('Given object of type "' . get_class($enrichment) . '" is not valid: ' . PHP_EOL . $violations);
     }
     $status = $this->storageBackend->post($enrichment);
     return $status;
 }
開發者ID:aoemedia,項目名稱:searchperience-api-client,代碼行數:16,代碼來源:EnrichmentRepository.php

示例8: validate

 /**
  * {@inheritdoc}
  */
 public function validate($entity, array $columnsInfo, array $data, array $errors = array())
 {
     $this->checkIdentifier($entity, $columnsInfo, $data);
     if (!count($errors)) {
         return $this->getErrorMap($this->validator->validate($entity));
     } else {
         return $this->validateProperties($entity, $columnsInfo) + $errors;
     }
 }
開發者ID:vpetrovych,項目名稱:pim-community-dev,代碼行數:12,代碼來源:ImportValidator.php

示例9: validateFilter

 /**
  * @param object $filter
  * @throws \Searchperience\Common\Exception\InvalidArgumentException
  */
 protected function validateFilter($filter)
 {
     $this->loadConstraints();
     $this->injectValidator(\Symfony\Component\Validator\Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator());
     $violations = $this->filterValidator->validate($filter);
     if ($violations->count() > 0) {
         throw new \Searchperience\Common\Exception\InvalidArgumentException('Given object of type "' . get_class($violations) . '" is not valid: ' . $violations);
     }
 }
開發者ID:aoemedia,項目名稱:searchperience-api-client,代碼行數:13,代碼來源:AbstractFilterCollectionFactory.php

示例10: validate

 /**
  * @{inheritdoc}
  */
 public function validate($object, Violation\ViolationList $violationList)
 {
     $errors = $this->validator->validate($object);
     foreach ($errors as $error) {
         $constraint = call_user_func_array(array($this->model, 'createFromConstraintViolation'), array($error));
         $violationList->add($constraint);
     }
     return $violationList;
 }
開發者ID:rezzza,項目名稱:ModelViolationLoggerBundle,代碼行數:12,代碼來源:SymfonyValidatorHandler.php

示例11: add

 /**
  * Add a new Document to the index
  *
  * @param \Searchperience\Api\Client\Domain\UrlQueueItem\UrlQueueItem $urlQueueItem
  * @throws \Searchperience\Common\Exception\InvalidArgumentException
  * @return integer HTTP Status code
  */
 public function add(\Searchperience\Api\Client\Domain\UrlQueueItem\UrlQueueItem $urlQueueItem)
 {
     $violations = $this->urlQueueValidator->validate($urlQueueItem);
     if ($violations->count() > 0) {
         throw new InvalidArgumentException('Given object of type "' . get_class($urlQueueItem) . '" is not valid: ' . PHP_EOL . $violations);
     }
     $status = $this->storageBackend->post($urlQueueItem);
     return $status;
 }
開發者ID:aoemedia,項目名稱:searchperience-api-client,代碼行數:16,代碼來源:UrlQueueItemRepository.php

示例12: validate

 /**
  * @param object $object
  */
 public function validate($object)
 {
     $flattenedErros = array();
     $errors = $this->validator->validate($object);
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             $flattenedErros[$error->getPropertyPath()] = $error->getMessage();
         }
         throw new InvalidException("Object is invalid", $flattenedErros);
     }
 }
開發者ID:jroussay,項目名稱:rest-bundle,代碼行數:14,代碼來源:Validator.php

示例13: saveCart

 public function saveCart(CartEvent $event)
 {
     $cart = $event->getCart();
     $errors = $this->validator->validate($cart);
     $valid = 0 === count($errors);
     if ($valid) {
         $this->cartManager->persist($cart);
         $this->cartManager->flush();
         $this->cartProvider->setCart($cart);
     }
 }
開發者ID:bcremer,項目名稱:Sylius,代碼行數:11,代碼來源:CartListener.php

示例14: validateEntity

 /**
  * Validate entity, returns list of errors or null
  *
  * @param object $entity
  * @return array|null
  */
 public function validateEntity($entity)
 {
     $violations = $this->validator->validate($entity);
     if (count($violations)) {
         $errors = array();
         /** @var ConstraintViolationInterface $violation */
         foreach ($violations as $violation) {
             $errors[] = sprintf(sprintf('%s: %s', $violation->getPropertyPath(), $violation->getMessage()));
         }
         return $errors;
     }
     return null;
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:19,代碼來源:ImportStrategyHelper.php

示例15: validateEntity

 /**
  * Validates one entity.
  *
  * @param BaseEntity $entity
  * @throws \App\Exceptions\EntityValidationException
  */
 private function validateEntity(BaseEntity $entity)
 {
     /** @var ConstraintViolationListInterface $violationList */
     $violationList = $this->validator->validate($entity);
     if ($violationList->count() > 0) {
         $msg = "";
         /** @var ConstraintViolationInterface $violation */
         foreach ($violationList as $violation) {
             $msg .= get_class($violation->getRoot()) . '::$' . $violation->getPropertyPath();
             $msg .= ' ' . $violation->getMessage() . PHP_EOL;
         }
         throw new EntityValidationException($msg);
     }
 }
開發者ID:mike227,項目名稱:n-sandbox,代碼行數:20,代碼來源:EntityValidatorSubscriber.php


注:本文中的Symfony\Component\Validator\ValidatorInterface::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。