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


PHP ExecutionContextInterface::addViolation方法代碼示例

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


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

示例1: verifyCountryList

 public function verifyCountryList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Country list is not valid JSON"));
     }
     $countryList = json_decode($value, true);
     foreach ($countryList as $countryItem) {
         if (is_array($countryItem)) {
             $country = CountryQuery::create()->findPk($countryItem[0]);
             if (null === $country) {
                 $context->addViolation(Translator::getInstance()->trans("Country ID %id not found", ['%id' => $countryItem[0]]));
             }
             if ($countryItem[1] == "0") {
                 continue;
             }
             $state = StateQuery::create()->findPk($countryItem[1]);
             if (null === $state) {
                 $context->addViolation(Translator::getInstance()->trans("State ID %id not found", ['%id' => $countryItem[1]]));
             }
         } else {
             $context->addViolation(Translator::getInstance()->trans("Wrong country definition"));
         }
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:25,代碼來源:TaxRuleTaxListUpdateForm.php

示例2: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     parent::validate($value, $constraint);
     $host = substr($value, strpos($value, '@') + 1);
     if (in_array($host, $this->blacklist)) {
         $this->context->addViolation($constraint->message, ['%host%' => $host]);
     }
 }
開發者ID:xyNNN,項目名稱:BlacklistedEmailValidatorBundle,代碼行數:11,代碼來源:BlacklistedEmailValidator.php

示例3: verifyDeliveryModule

 public function verifyDeliveryModule($value, ExecutionContextInterface $context)
 {
     $module = ModuleQuery::create()->filterActivatedByTypeAndId(BaseModule::DELIVERY_MODULE_TYPE, $value)->findOne();
     if (null === $module) {
         $context->addViolation(Translator::getInstance()->trans("Delivery module ID not found"));
     } elseif (!$module->isDeliveryModule()) {
         $context->addViolation(sprintf(Translator::getInstance()->trans("delivery module %s is not a Thelia\\Module\\DeliveryModuleInterface"), $module->getCode()));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:9,代碼來源:OrderDelivery.php

示例4: verifyPasswordField

 public function verifyPasswordField($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if ($data["password"] != $data["password_confirm"]) {
         $context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
     }
     if ($data["password"] !== '' && strlen($data["password"]) < 4) {
         $context->addViolation(Translator::getInstance()->trans("password must be composed of at least 4 characters"));
     }
 }
開發者ID:gillesbourgeat,項目名稱:core,代碼行數:10,代碼來源:AdministratorModificationForm.php

示例5: checkStateId

 public function checkStateId($value, ExecutionContextInterface $context)
 {
     if ($value['migrate']) {
         if (null !== ($state = StateQuery::create()->findPk($value['new_state']))) {
             if ($state->getCountryId() !== $value['new_country']) {
                 $context->addViolation(Translator::getInstance()->trans("The state id '%id' does not belong to country id '%id_country'", ['%id' => $value['new_state'], '%id_country' => $value['new_country']]));
             }
         } else {
             $context->addViolation(Translator::getInstance()->trans("The state id '%id' doesn't exist", ['%id' => $value['new_state']]));
         }
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:12,代碼來源:CountryStateMigrationType.php

示例6: verifyPasswordField

 public function verifyPasswordField($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if ($data["password"] === '' && $data["password_confirm"] === '') {
         $context->addViolation("password can't be empty");
     }
     if ($data["password"] != $data["password_confirm"]) {
         $context->addViolation("password confirmation is not the same as password field");
     }
     $minLength = ConfigQuery::getMinimuAdminPasswordLength();
     if (strlen($data["password"]) < $minLength) {
         $context->addViolation("password must be composed of at least {$minLength} characters");
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:14,代碼來源:AdminCreatePassword.php

示例7: verifyState

 public function verifyState($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (null !== ($country = CountryQuery::create()->findPk($data['country']))) {
         if ($country->getHasStates()) {
             if (null !== ($state = StateQuery::create()->findPk($data['state']))) {
                 if ($state->getCountryId() !== $country->getId()) {
                     $context->addViolation(Translator::getInstance()->trans("This state doesn't belong to this country."));
                 }
             } else {
                 $context->addViolation(Translator::getInstance()->trans("You should select a state for this country."));
             }
         }
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:15,代碼來源:AddressCountryValidationTrait.php

示例8: checkDate

 /**
  * Validate a date entered with the current edition Language date format.
  *
  * @param string                    $value
  * @param ExecutionContextInterface $context
  */
 public function checkDate($value, ExecutionContextInterface $context)
 {
     $format = self::PHP_DATE_FORMAT;
     if (!empty($value) && false === \DateTime::createFromFormat($format, $value)) {
         $context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", ['%fmt' => self::MOMENT_JS_DATE_FORMAT, '%date' => $value]));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:13,代碼來源:SaleModificationForm.php

示例9: checkRefDifferent

 public function checkRefDifferent($value, ExecutionContextInterface $context)
 {
     $originalRef = ProductQuery::create()->filterByRef($value, Criteria::EQUAL)->count();
     if ($originalRef !== 0) {
         $context->addViolation($this->translator->trans('This product reference is already assigned to another product.'));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:7,代碼來源:ProductCloneForm.php

示例10: verifyCountry

 public function verifyCountry($value, ExecutionContextInterface $context)
 {
     $address = CountryQuery::create()->findPk($value);
     if (null === $address) {
         $context->addViolation(Translator::getInstance()->trans("Country ID not found"));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:7,代碼來源:OrderUpdateAddress.php

示例11: verifyExistingEmail

 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("You are already registered!"));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:7,代碼來源:NewsletterForm.php

示例12: checkDuplicateName

 public function checkDuplicateName($value, ExecutionContextInterface $context)
 {
     $config = ConfigQuery::create()->findOneByName($value);
     if ($config) {
         $context->addViolation(Translator::getInstance()->trans('A variable with name "%name" already exists.', array('%name' => $value)));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:7,代碼來源:ConfigCreationForm.php

示例13: verifyExistingCode

 public function verifyExistingCode($value, ExecutionContextInterface $context)
 {
     $coupon = CouponQuery::create()->findOneByCode($value);
     if (null === $coupon) {
         $context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:7,代碼來源:CouponCode.php

示例14: isDataValid

 /**
  * @Assert\Callback(groups={"flow_revalidatePreviousSteps_step1"})
  */
 public function isDataValid(ExecutionContextInterface $context)
 {
     // valid only on first call
     if (++self::$validationCalls > 1) {
         $context->addViolation('Take this!');
     }
 }
開發者ID:Nairebis,項目名稱:CraueFormFlowBundle,代碼行數:10,代碼來源:RevalidatePreviousStepsData.php

示例15: verifyExistingEmail

 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::getCustomerByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("This email already exists."));
     }
 }
開發者ID:vigourouxjulien,項目名稱:thelia,代碼行數:7,代碼來源:CustomerCreateForm.php


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