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


PHP ExecutionContext::addViolationAt方法代码示例

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


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

示例1: testAddViolationAtUsesPassedNullValue

 public function testAddViolationAtUsesPassedNullValue()
 {
     $this->translator->expects($this->once())->method('trans')->with('Error', array('foo' => 'bar'))->will($this->returnValue('Translated error'));
     $this->translator->expects($this->once())->method('transChoice')->with('Choice error', 2, array('foo' => 'bar'))->will($this->returnValue('Translated choice error'));
     // passed null value should override preconfigured value "invalid"
     $this->context->addViolationAt('bam.baz', 'Error', array('foo' => 'bar'), null);
     $this->context->addViolationAt('bam.baz', 'Choice error', array('foo' => 'bar'), null, 2);
     $this->assertEquals(new ConstraintViolationList(array(new ConstraintViolation('Translated error', 'Error', array('foo' => 'bar'), 'Root', 'foo.bar.bam.baz', null), new ConstraintViolation('Translated choice error', 'Choice error', array('foo' => 'bar'), 'Root', 'foo.bar.bam.baz', null, 2))), $this->context->getViolations());
 }
开发者ID:shomimn,项目名称:builder,代码行数:9,代码来源:LegacyExecutionContextTest.php

示例2:

 function it_validates_if_user_with_given_email_is_already_registered(UserRepository $userRepository, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, ExecutionContext $context, TokenInterface $token, UniqueReviewerEmail $constraint, ReviewInterface $review, CustomerInterface $customer, CustomerInterface $existingUser)
 {
     $tokenStorage->getToken()->willReturn($token);
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(false);
     $review->getAuthor()->willReturn($customer);
     $customer->getEmail()->willReturn('john.doe@example.com');
     $userRepository->findOneByEmail('john.doe@example.com')->willReturn($existingUser);
     $constraint->message = 'This email is already registered. Please log in.';
     $context->addViolationAt('author', 'This email is already registered. Please log in.', [], null)->shouldBeCalled();
     $this->validate($review, $constraint);
 }
开发者ID:TheMadeleine,项目名称:Sylius,代码行数:11,代码来源:UniqueReviewerEmailValidatorSpec.php

示例3: validate

 /**
  * Validates contact method
  *
  * @param ContactRequest   $object
  * @param ExecutionContext $context
  */
 public static function validate(ContactRequest $object, ExecutionContext $context)
 {
     $emailError = $phoneError = false;
     switch ($object->getPreferredContactMethod()) {
         case ContactRequest::CONTACT_METHOD_PHONE:
             $phoneError = !$object->getPhone();
             break;
         case ContactRequest::CONTACT_METHOD_EMAIL:
             $emailError = !$object->getEmailAddress();
             break;
         case ContactRequest::CONTACT_METHOD_BOTH:
         default:
             $phoneError = !$object->getPhone();
             $emailError = !$object->getEmailAddress();
     }
     if ($emailError) {
         $context->addViolationAt('emailAddress', 'This value should not be blank.');
     }
     if ($phoneError) {
         $context->addViolationAt('phone', 'This value should not be blank.');
     }
 }
开发者ID:dairdr,项目名称:crm,代码行数:28,代码来源:ContactRequestCallbackValidator.php

示例4: areImagesValid

 public function areImagesValid(ExecutionContext $context)
 {
     $captured_ids = array_map(function ($image) {
         return $image->getId();
     }, $this->images->toArray());
     $property_path = $context->getPropertyPath() . '.images';
     if (!count($captured_ids)) {
         $context->addViolationAt($property_path, 'Please select at least one image!', array(), null);
         return;
     }
     $count = $this->query_builder->andWhere($this->query_builder->expr()->in('i.id', $captured_ids))->select('COUNT(i.id)')->getQuery()->getSingleScalarResult();
     if (!$count) {
         $context->addViolation('Please select images from the list!', array(), null);
     }
 }
开发者ID:rodgermd,项目名称:mura-show.com,代码行数:15,代码来源:BulkImages.php

示例5: isRegionValid

 public function isRegionValid(ExecutionContext $context)
 {
     if ($this->getCountry() && $this->getCountry()->hasRegions() && !$this->region && !$this->regionText) {
         // do not allow saving text region in case when region was checked from list
         // except when in base data region text existed
         // another way region_text field will be null, logic are placed in form listener
         $propertyPath = $context->getPropertyPath() . '.region';
         $context->addViolationAt($propertyPath, 'Region is required for country %country%', array('%country%' => $this->getCountry()->getName()));
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:10,代码来源:AbstractAddress.php

示例6: isRegionValid

 public function isRegionValid(ExecutionContext $context)
 {
     if ($this->getCountry() && $this->getCountry()->hasRegions() && !$this->state) {
         $propertyPath = $context->getPropertyPath() . '.state';
         $context->addViolationAt($propertyPath, 'State is required for country %country%', array('%country%' => $this->getCountry()->getName()));
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:7,代码来源:AbstractAddress.php

示例7: isValid

 /**
  * Custom validation constraint
  * Not valid if no one recipient specified
  *
  * @param ExecutionContext $context
  */
 public function isValid(ExecutionContext $context)
 {
     $notValid = $this->getGroups()->isEmpty() && $this->getUsers()->isEmpty() && $this->getEmail() == null && $this->getOwner() == null;
     if ($notValid) {
         $propertyPath = $context->getPropertyPath() . '.recipientList';
         $context->addViolationAt($propertyPath, 'oro.notification.validators.recipient_list.empty.message');
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:14,代码来源:RecipientList.php

示例8: isPackageUnique

 public function isPackageUnique(ExecutionContext $context)
 {
     try {
         if ($this->entityRepository->findOneByName($this->name)) {
             $context->addViolationAt('repository', 'A package with the name <a href="' . $this->router->generate('view_package', array('name' => $this->name)) . '">' . $this->name . '</a> already exists.', array(), null);
         }
     } catch (\Doctrine\ORM\NoResultException $e) {
     }
 }
开发者ID:rdohms,项目名称:packagist,代码行数:9,代码来源:Package.php

示例9: validate

 /**
  * validate
  *
  * @param type             $data
  * @param ExecutionContext $context
  */
 public function validate($data, ExecutionContext $context)
 {
     if ($data['mode'] === 'add_favorite') {
         if (!$this->security->isGranted('ROLE_USER')) {
             $context->addViolationAt('', 'ログインしてください.');
         }
     } else {
         $context->validateValue($data['product_class_id'], array(new Assert\NotBlank()), '[product_class_id]');
         if ($this->Product->getClassName1()) {
             $context->validateValue($data['classcategory_id1'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'This value should be blank.'))), '[classcategory_id1]');
         }
         if ($this->Product->getClassName2()) {
             $context->validateValue($data['classcategory_id2'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'This value should be blank.'))), '[classcategory_id2]');
         }
     }
 }
开发者ID:nanasess,项目名称:nagoya-eccube-study,代码行数:22,代码来源:AddCartType.php

示例10: isExpireDateValid

 public function isExpireDateValid(ExecutionContext $context)
 {
     $now = new \DateTime();
     $thisYear = (int) $now->format('Y');
     $thisMonth = (int) $now->format('m');
     $expYear = (int) $this->getExpiryDateYear();
     $expMonth = (int) $this->getExpiryDateMonth();
     if ($thisYear > $expYear || $thisYear == $expYear && $thisMonth > $expMonth) {
         $context->addViolationAt('expiry_date_month', 'expired card', array(), null);
     }
 }
开发者ID:leaphly,项目名称:leaphly-sandbox,代码行数:11,代码来源:CreditCard.php

示例11: isUnderTotalConstraint

 public function isUnderTotalConstraint(ExecutionContext $context)
 {
     $this->getFreeTotal($credit, $debit);
     // compare with an epsilon, we're using floats here!
     if ($credit < -0.001) {
         $context->addViolationAt('credit', 'Le total des factures dépasse le crédit de la ligne de %depassement% €', array('%depassement%' => round($credit, 2) * -1), null);
     }
     if ($debit < -0.001) {
         $context->addViolationAt('debit', 'Le total des factures dépasse le débit de la ligne de %depassement% €', array('%depassement%' => round($debit, 2) * -1), null);
     }
 }
开发者ID:romaricdrigon,项目名称:LogicielTrez-Symfony,代码行数:11,代码来源:Ligne.php

示例12: checkPasswordLength

 public function checkPasswordLength(ExecutionContext $context)
 {
     if ($this->can_credentials === true && mb_strlen($this->password, 'UTF-8') < 6) {
         $context->addViolationAt('password', "Le mot de passe doit faire au minimum 6 caractères");
     }
 }
开发者ID:romaricdrigon,项目名称:LogicielTrez-Symfony,代码行数:6,代码来源:User.php

示例13: isTvasCorrect

 public function isTvasCorrect(ExecutionContext $context)
 {
     $montant_ht = 0;
     foreach ($this->tvas as $tva) {
         $montant_ht += $tva->getMontantHt();
     }
     if (abs($this->montant - $montant_ht) > 0.001) {
         // floats -> epsilon!
         $context->addViolationAt('tvas', 'La somme des montants HT doit être égale au montant de la facture');
     }
 }
开发者ID:romaricdrigon,项目名称:LogicielTrez-Symfony,代码行数:11,代码来源:Facture.php

示例14: isPhoneValid

 public function isPhoneValid(ExecutionContext $context)
 {
     if (!$this->getPhoneNumber() && !$this->getContactPhoneNumber()) {
         $propertyPath = $context->getPropertyPath() . '.contactPhoneNumber';
         $context->addViolationAt($propertyPath, 'orocrm.call.phone.required.message');
     }
 }
开发者ID:dairdr,项目名称:crm,代码行数:7,代码来源:Call.php


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