php Symfony-Component-Validator-ValidatorInterface类(方法)实例源码

下面列出了php Symfony-Component-Validator-ValidatorInterface 类(方法)源码代码实例,从而了解它的用法。

作者:davidbadur    项目:fixture   
public function setUp()
 {
     parent::setUp();
     $this->validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
     $this->validator->expects($this->never())->method('validate')->will($this->returnValue(array()));
     $this->listener = new ValidationListener($this->validator);
 }

作者:skedon    项目:experience-ap   
private function validateXApiValidator(ValidatorInterface $validator)
 {
     $metadataFactory = $validator->getMetadataFactory();
     $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Activity'));
     $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Agent'));
     $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Activity'));
     $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Activity'));
 }

作者:repa    项目:data-impor   
function it_validates_an_item_and_the_validation_fails_with_exception(ValidatorInterface $validator, Constraint $constraint, ConstraintViolationList $list)
 {
     $list->count()->willReturn(1);
     $validator->validateValue($this->item1, Argument::type('Symfony\\Component\\Validator\\Constraints\\Collection'))->willReturn($list);
     $this->throwExceptions(true);
     $this->add('key1', $constraint);
     $this->shouldThrow('Ddeboer\\DataImport\\Exception\\ValidationException')->during__invoke($this->item1);
     $this->getViolations()->shouldReturn([1 => $list]);
 }

作者:xabbu    项目:xapi-validato   
private function validateXApiValidator(ValidatorInterface $validator)
 {
     if ($validator instanceof MetadataFactoryInterface) {
         $metadataFactory = $validator;
     } else {
         $metadataFactory = $validator->getMetadataFactory();
     }
     $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Activity'));
     $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Agent'));
     $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Activity'));
     $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Activity'));
 }

作者:kuba199    项目:DoctrineForm   
/**
  * @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");
         }
     }
 }

作者:Maksol    项目:platfor   
/**
  * Validate data
  *
  * @param EntityData $data
  * @throws ValidationException
  */
 public function run(EntityData $data)
 {
     $constraintViolations = $this->validator->validate($data);
     if ($constraintViolations->count()) {
         throw new ValidationException($constraintViolations);
     }
 }

作者:mvanduijke    项目:FMIoBundl   
/**
  * @param SourceInterface $source
  *
  * @throws ValidationException
  */
 protected function validate(SourceInterface $source)
 {
     $violations = $this->validator->validate($source);
     if ($violations->count()) {
         throw ValidationException::create($violations);
     }
 }

作者:vpetrovyc    项目:pim-community-de   
/**
  * {@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;
 }

作者:tweedegol    项目:generato   
/**
  * @param string|InputTypeInterface $type
  * @param array                     $options
  * @param Constraint[]|Constraint   $constraints
  * @return mixed
  * @throws InputTypeNotFoundException
  */
 public function ask($type, array $options = [])
 {
     if (is_string($type)) {
         $type = $this->types->getType($type);
     }
     if (!$type instanceof InputTypeInterface) {
         throw new InputTypeNotFoundException("Type should be an instance of InputTypeInterface or a string");
     }
     $options = $this->validateAndUpdateOptions($options, $type);
     $value = $options['default'];
     while (true) {
         $value = $type->ask($options, $this);
         if (is_callable($options['modify'])) {
             $value = call_user_func($options['modify'], $value);
         }
         if ($options['constraints'] !== null) {
             $problems = $this->validator->validateValue($value, $options['constraints']);
             if (count($problems) > 0) {
                 $messages = ["There were some errors in the provided value:", ""];
                 /** @var ConstraintViolation $problem */
                 foreach ($problems as $problem) {
                     $messages[] = "{$problem->getMessage()}";
                 }
                 /** @var FormatterHelper $formatter */
                 $formatter = $this->getHelper('formatter');
                 $this->getOutput()->writeln($formatter->formatBlock($messages, 'error', true));
                 continue;
             }
         }
         break;
     }
     return $value;
 }

作者:seiffer    项目:controller-helper-bundl   
/**
  * @param mixed $data
  * @throws MissingDependencyException
  */
 public function validate($data)
 {
     if (!$this->validator) {
         throw new MissingDependencyException('No validator present.');
     }
     return $this->validator->validate($data);
 }

作者:alehers    项目:Syliu   
/**
  * {@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));
     }
 }

作者:silvestr    项目:medi   
/**
  * Validate upload image.
  *
  * @param UploadedFile $uploadedImage
  * @param array $config
  *
  * @return array
  */
 private function validateUploadImage(UploadedFile $uploadedImage, array $config)
 {
     $errors = array();
     foreach ($this->validator->validateValue($uploadedImage, $this->getConstraint($config)) as $error) {
         $errors[] = $error->getMessage();
     }
     return $errors;
 }

作者:aoemedi    项目:searchperience-api-clien   
/**
  * 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;
 }

作者:aoemedi    项目:searchperience-api-clien   
/**
  * @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);
     }
 }

作者:rezzz    项目:ModelViolationLoggerBundl   
/**
  * @{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;
 }

作者:aoemedi    项目:searchperience-api-clien   
/**
  * 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;
 }

作者:bcreme    项目:Syliu   
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);
     }
 }

作者:jroussa    项目:rest-bundl   
/**
  * @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);
     }
 }

作者:pvdlee    项目:UberFrontendValidationBundl   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $fieldName = $view->vars['full_name'];
     $parentForm = $form->getParent();
     if (!empty($parentForm)) {
         $config = $parentForm->getConfig();
         $options = $config->getOptions();
         $validationGroups = $options['validation_groups'];
         $dataClass = $config->getDataClass();
         $entityMetadata = $dataClass !== null ? $this->validator->getMetadataFor($dataClass) : null;
         $view->vars['entity_constraints'] = $this->prepareConstraintsAttributes($fieldName, $entityMetadata, $validationGroups);
     }
 }

作者:ashutosh-srija    项目:findit_akene   
/**
  * 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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号