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


PHP ConstraintViolationList::addAll方法代码示例

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


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

示例1: onKernelController

 /**
  * Core request handler.
  *
  * @param GetResponseEvent $event The event
  *
  * @throws BadRequestHttpException
  * @throws UnsupportedMediaTypeHttpException
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $metadata = $this->getControllerActionMetadata($controller);
     if (null !== $metadata) {
         $violations = new ConstraintViolationList();
         if (0 < count($metadata->queryParams)) {
             // set defaults
             $this->setDefaultValues($metadata->queryParams, $request->query);
             $queryViolations = $this->validateParams($this->container->get('validator'), $metadata->queryParams, $request->query);
             $violations->addAll($queryViolations);
         }
         if (0 < count($metadata->requestParams)) {
             // set defaults
             $this->setDefaultValues($metadata->requestParams, $request->request);
             $requestViolations = $this->validateParams($this->container->get('validator'), $metadata->requestParams, $request->request);
             $violations->addAll($requestViolations);
         }
         $violationParam = $this->getViolationsParameterName($metadata);
         if (null !== $violationParam) {
             // if action has an argument for violations, pass it
             $request->attributes->set($violationParam, $violations);
         } elseif (0 < count($violations)) {
             // if action has no arg for violations and there is at least one, throw an exception
             throw new ValidationException($violations);
         }
     }
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:37,代码来源:ValidationListener.php

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

示例3: validate

 /**
  * {@inheritdoc}
  */
 public function validate($prices, array $options = [], $attributeCode)
 {
     $violations = new ConstraintViolationList();
     foreach ($prices as $price) {
         if (isset($price['data']) && ($valid = parent::validate($price['data'], $options, $attributeCode))) {
             $violations->addAll($valid);
         }
     }
     return $violations->count() > 0 ? $violations : null;
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:13,代码来源:PriceLocalizer.php

示例4: ConstraintViolation

 function it_returns_a_constraint_if_the_decimal_separator_is_not_valid($validator)
 {
     $constraintUSD = new ConstraintViolation('Error on number validator', '', [], '', '', '');
     $constraintEUR = new ConstraintViolation('Error on number validator', '', [], '', '', '');
     $constraints = new ConstraintViolationList([$constraintEUR, $constraintUSD]);
     $validator->validate('10,00', Argument::any())->willReturn($constraints);
     $validator->validate('10,05', Argument::any())->willReturn(null);
     $prices = [['data' => '10,00', 'currency' => 'EUR'], ['data' => '10,05', 'currency' => 'USD']];
     $allConstraints = new ConstraintViolationList();
     $allConstraints->addAll($constraints);
     $this->validate($prices, ['decimal_separator' => ','], 'prices')->shouldHaveCount(2);
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:12,代码来源:PriceLocalizerSpec.php

示例5: isValidRedirectUrl

 /**
  * Checks whether the given value is a valid URL that may probably be safely used as a redirect url.
  *
  * @param string $value URL to validate
  *
  * @return boolean true if the url is correct
  */
 protected function isValidRedirectUrl($value)
 {
     $validator = Validation::createValidator();
     $constraints = array(new Constraints\Type(array('type' => 'string')), new Constraints\Length(array('min' => $this->getParameter('min_length', 10), 'max' => $this->getParameter('max_length', 1000))), new Constraints\Url(array('protocols' => $this->getParameter('allowed_protocols', array('http', 'https')))));
     if ($this->getParameter('check_base_href', true)) {
         $constraints[] = new Constraints\Callback(array('methods' => array(array($this, 'hasCorrectBaseHref'))));
     }
     $violations = new ConstraintViolationList();
     foreach ($constraints as $constraint) {
         $violations->addAll($validator->validateValue($value, $constraint));
     }
     if ($violations->count() === 0) {
         return true;
     } else {
         $this->getContext()->getLoggerManager()->logTo('default', \AgaviLogger::WARNING, __METHOD__, $violations->__toString());
         return false;
     }
 }
开发者ID:honeybee,项目名称:honeybee-agavi-cmf-vendor,代码行数:25,代码来源:RedirectValidator.php

示例6: validate

 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      ValidatorInterface|null $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         $validator = new RecursiveValidator(new ExecutionContextFactory(new IdentityTranslator()), new LazyLoadingMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         // If validate() method exists, the validate-behavior is configured for related object
         if (method_exists($this->aOwner, 'validate')) {
             if (!$this->aOwner->validate($validator)) {
                 $failureMap->addAll($this->aOwner->getValidationFailures());
             }
         }
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collPackPermissions) {
             foreach ($this->collPackPermissions as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collUserGroups) {
             foreach ($this->collUserGroups as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }
开发者ID:xfreddiex,项目名称:code-sharer,代码行数:53,代码来源:Group.php

示例7: validateContexts

 /**
  * {@inheritdoc}
  */
 public function validateContexts()
 {
     $violations = new ConstraintViolationList();
     // @todo: Implement symfony validator API to let the validator traverse
     // and set property paths accordingly.
     foreach ($this->getContexts() as $context) {
         $violations->addAll($context->validate());
     }
     return $violations;
 }
开发者ID:318io,项目名称:318-io,代码行数:13,代码来源:ContextAwarePluginBase.php

示例8: validate

 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      object $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         if (class_exists('Symfony\\Component\\Validator\\Validator\\LegacyValidator')) {
             $validator = new LegacyValidator(new ExecutionContextFactory(new DefaultTranslator()), new ClassMetaDataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
         } else {
             $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator());
         }
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         // If validate() method exists, the validate-behavior is configured for related object
         if (method_exists($this->aInterested, 'validate')) {
             if (!$this->aInterested->validate($validator)) {
                 $failureMap->addAll($this->aInterested->getValidationFailures());
             }
         }
         // If validate() method exists, the validate-behavior is configured for related object
         if (method_exists($this->aTarget_Event, 'validate')) {
             if (!$this->aTarget_Event->validate($validator)) {
                 $failureMap->addAll($this->aTarget_Event->getValidationFailures());
             }
         }
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }
开发者ID:Web-Systems-Development-Team,项目名称:RPIwannahangout,代码行数:45,代码来源:EventInterest.php

示例9: validate

 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      ValidatorInterface|null $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         $validator = new RecursiveValidator(new ExecutionContextFactory(new IdentityTranslator()), new LazyLoadingMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collPermissionGroupUsers) {
             foreach ($this->collPermissionGroupUsers as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyrics) {
             foreach ($this->collLyrics as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricTranslations) {
             foreach ($this->collLyricTranslations as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricVotes) {
             foreach ($this->collLyricVotes as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collArtists) {
             foreach ($this->collArtists as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collAlbums) {
             foreach ($this->collAlbums as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }
开发者ID:Tekstove,项目名称:Tekstove-api,代码行数:79,代码来源:User.php

示例10: onKernelController

 /**
  * Controller.
  *
  * @param FilterControllerEvent $event The event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $this->request = $event->getRequest();
     if ($request->attributes->has('start') && $request->attributes->has('count')) {
         return;
     }
     if (false === $this->isEnabled()) {
         return;
     }
     $controller = $event->getController();
     if (false === in_array($request->getMethod(), array('GET', 'HEAD', 'DELETE'))) {
         // pagination only makes sense with GET or DELETE methods
         return;
     }
     $metadata = $this->getControllerActionMetadata($controller);
     if (null === $metadata || null === $metadata->default_start) {
         // no annotations defined for this controller
         return;
     }
     $start = $metadata->default_start;
     $count = $metadata->default_count;
     $range = explode(',', $request->headers->get('Range'));
     if (true === isset($range[0])) {
         $start = intval($range[0]);
     }
     if (true === isset($range[1])) {
         $count = intval($range[1]);
     }
     $violations = new ConstraintViolationList();
     $start_violations = $this->validator->validateValue($start, array(new \Symfony\Component\Validator\Constraints\Type(array('type' => 'numeric', 'message' => 'Headers "Range" attribute first operand (=start) must be a positive integer')), new \Symfony\Component\Validator\Constraints\Range(array('min' => 0, 'minMessage' => 'Headers "Range" attribute first operand (=start) must be a positive integer'))));
     $count_label = 'Headers "Range" attribute second operand (=count)';
     $count_violations = $this->validator->validateValue($count, array(new \Symfony\Component\Validator\Constraints\Type(array('type' => 'numeric', 'message' => "{$count_label} must be a positive integer")), new \Symfony\Component\Validator\Constraints\Range(array('min' => $metadata->min_count, 'minMessage' => "{$count_label} must be greater than or equal to " . $metadata->min_count, 'max' => $metadata->max_count, 'maxMessage' => "{$count_label} must be less than or equal to " . $metadata->max_count))));
     $violations->addAll($start_violations);
     $violations->addAll($count_violations);
     $violation_param = $this->getViolationsParameterName($metadata);
     if (null !== $violation_param) {
         // if action has an argument for violations, pass it
         $request->attributes->set($violation_param, $violations);
     } elseif (0 < count($violations)) {
         // if action has no arg for violations and there is at least one, throw an exception
         throw new ValidationException($violations);
     }
     // add pagination properties to attributes
     $request->attributes->set('start', $start);
     $request->attributes->set('count', $count);
     // remove pagination properties from headers
     $request->headers->remove('Range');
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:53,代码来源:PaginationListener.php

示例11: validateObject

 /**
  * Validates an object using fields validators
  *
  * @param object $object
  */
 public function validateObject($object)
 {
     if ($this->validationMethod === self::VALIDATE_WITH_METHOD) {
         if (!method_exists($object, 'validate')) {
             return true;
         }
         if (!call_user_func(array($object, 'validate'))) {
             $violations = implode("\n", $object->getValidationFailures());
             throw new ValidationException($violations);
         }
         return true;
     }
     if ($this->validationMethod === self::VALIDATE_WITH_CALLBACK) {
         if ($this->validator === null) {
             throw new DefinitionBuilderException("Missing validation callback");
         }
         return call_user_func($this->validator, array($object, $this));
     }
     if ($this->validator === null) {
         return true;
     }
     if ($this->className !== null) {
         $violiations = $this->validator->validate($object);
     } else {
         $violiations = new ConstraintViolationList();
         foreach ($this->fields as $field) {
             $value = $field->getValue($object);
             $violiations->addAll($this->validator->validateValue($value, $field->getConstraints()));
         }
     }
     if (count($violiations)) {
         throw new ValidationException($violiations);
     }
     return true;
 }
开发者ID:mpoiriert,项目名称:nucleus,代码行数:40,代码来源:ModelDefinition.php

示例12: validate

 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      object $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(Validator $validator = null)
 {
     if (null === $validator) {
         $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator());
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         // If validate() method exists, the validate-behavior is configured for related object
         if (method_exists($this->aDiaporama, 'validate')) {
             if (!$this->aDiaporama->validate($validator)) {
                 $failureMap->addAll($this->aDiaporama->getValidationFailures());
             }
         }
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collDiaporamaImageI18ns) {
             foreach ($this->collDiaporamaImageI18ns as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }
开发者ID:InformatiqueProg,项目名称:Diaporamas,代码行数:44,代码来源:DiaporamaImage.php

示例13: validate

 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      object $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         if (class_exists('Symfony\\Component\\Validator\\Validator\\LegacyValidator')) {
             $validator = new LegacyValidator(new ExecutionContextFactory(new DefaultTranslator()), new ClassMetaDataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
         } else {
             $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator());
         }
     }
     $failureMap = new ConstraintViolationList();
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collEvents) {
             foreach ($this->collEvents as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collInterests) {
             foreach ($this->collInterests as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collComments) {
             foreach ($this->collComments as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     $this->validationFailures = $failureMap;
     return (bool) (!(count($this->validationFailures) > 0));
 }
开发者ID:Web-Systems-Development-Team,项目名称:RPIwannahangout,代码行数:56,代码来源:User.php


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