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


PHP ExecutionContextInterface::addViolation方法代码示例

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


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

示例1: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (isset($value)) {
         $url_is_valid = TRUE;
         /** @var $link_item \Drupal\link\LinkItemInterface */
         $link_item = $value;
         $link_type = $link_item->getFieldDefinition()->getSetting('link_type');
         $url_string = $link_item->url;
         // Validate the url property.
         if ($url_string !== '') {
             try {
                 // @todo This shouldn't be needed, but massageFormValues() may not
                 //   run.
                 $parsed_url = UrlHelper::parse($url_string);
                 $url = Url::createFromPath($parsed_url['path']);
                 if ($url->isExternal() && !UrlHelper::isValid($url_string, TRUE)) {
                     $url_is_valid = FALSE;
                 } elseif ($url->isExternal() && !($link_type & LinkItemInterface::LINK_EXTERNAL)) {
                     $url_is_valid = FALSE;
                 }
             } catch (NotFoundHttpException $e) {
                 $url_is_valid = FALSE;
             } catch (MatchingRouteNotFoundException $e) {
                 $url_is_valid = FALSE;
             } catch (ParamNotConvertedException $e) {
                 $url_is_valid = FALSE;
             }
         }
         if (!$url_is_valid) {
             $this->context->addViolation($this->message, array('%url' => $url_string));
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:36,代码来源:LinkTypeConstraint.php

示例2: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (isset($value)) {
         $uri_is_valid = TRUE;
         /** @var $link_item \Drupal\link\LinkItemInterface */
         $link_item = $value;
         $link_type = $link_item->getFieldDefinition()->getSetting('link_type');
         // Try to resolve the given URI to a URL. It may fail if it's schemeless.
         try {
             $url = $link_item->getUrl();
         } catch (\InvalidArgumentException $e) {
             $uri_is_valid = FALSE;
         }
         // If the link field doesn't support both internal and external links,
         // check whether the URL (a resolved URI) is in fact violating either
         // restriction.
         if ($uri_is_valid && $link_type !== LinkItemInterface::LINK_GENERIC) {
             if (!($link_type & LinkItemInterface::LINK_EXTERNAL) && $url->isExternal()) {
                 $uri_is_valid = FALSE;
             }
             if (!($link_type & LinkItemInterface::LINK_INTERNAL) && !$url->isExternal()) {
                 $uri_is_valid = FALSE;
             }
         }
         if (!$uri_is_valid) {
             $this->context->addViolation($this->message, array('@uri' => $link_item->uri));
         }
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:32,代码来源:LinkTypeConstraint.php

示例3: 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:zorn-v,项目名称:thelia,代码行数:25,代码来源:TaxRuleTaxListUpdateForm.php

示例4: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (isset($value)) {
         try {
             /** @var \Drupal\Core\Url $url */
             $url = $value->getUrl();
         } catch (\InvalidArgumentException $e) {
             return;
         }
         if ($url->isRouted()) {
             $allowed = TRUE;
             try {
                 $url->toString();
             } catch (RouteNotFoundException $e) {
                 $allowed = FALSE;
             } catch (InvalidParameterException $e) {
                 $allowed = FALSE;
             } catch (MissingMandatoryParametersException $e) {
                 $allowed = FALSE;
             }
             if (!$allowed) {
                 $this->context->addViolation($constraint->message, array('@uri' => $value->uri));
             }
         }
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:29,代码来源:LinkNotExistingInternalConstraintValidator.php

示例5: verifyTaxList

 public function verifyTaxList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON"));
     }
     $taxList = json_decode($value, true);
     /* check we have 2 level max */
     foreach ($taxList as $taxLevel1) {
         if (is_array($taxLevel1)) {
             foreach ($taxLevel1 as $taxLevel2) {
                 if (is_array($taxLevel2)) {
                     $context->addViolation(Translator::getInstance()->trans("Bad tax list JSON"));
                 } else {
                     $taxModel = TaxQuery::create()->findPk($taxLevel2);
                     if (null === $taxModel) {
                         $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
                     }
                 }
             }
         } else {
             $taxModel = TaxQuery::create()->findPk($taxLevel1);
             if (null === $taxModel) {
                 $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
             }
         }
     }
 }
开发者ID:alex63530,项目名称:thelia,代码行数:28,代码来源:TaxRuleTaxListUpdateForm.php

示例6: validate

 /**
  * {@inheritdoc}
  */
 public function validate($items, Constraint $constraint)
 {
     if (isset($items)) {
         $date_values = $items->getValue();
         if ($date_values[0]['value'] >= $date_values[1]['value']) {
             $this->context->addViolation($constraint->message);
         }
     }
 }
开发者ID:balagan73,项目名称:cheppers_work,代码行数:12,代码来源:BalaganDateRangeConstraint.php

示例7: setMessage

 /**
  * Wrapper for $this->context->addViolation()
  *
  * @deprecated Deprecated since version 2.1, to be removed in 2.3.
  */
 protected function setMessage($template, array $parameters = array())
 {
     $this->messageTemplate = $template;
     $this->messageParameters = $parameters;
     if (!$this->context instanceof ExecutionContext) {
         throw new ValidatorException('ConstraintValidator::initialize() must be called before setting violation messages');
     }
     $this->context->addViolation($template, $parameters);
 }
开发者ID:netvlies,项目名称:symfony,代码行数:14,代码来源:ConstraintValidator.php

示例8: 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:margery,项目名称:thelia,代码行数:9,代码来源:OrderDelivery.php

示例9: 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:GuiminZHOU,项目名称:thelia,代码行数:10,代码来源:AdministratorModificationForm.php

示例10: setMessage

 /**
  * Wrapper for $this->context->addViolation()
  *
  * @deprecated Deprecated since version 2.1, to be removed in 2.3.
  */
 protected function setMessage($template, array $parameters = array())
 {
     trigger_error('setMessage() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
     $this->messageTemplate = $template;
     $this->messageParameters = $parameters;
     if (!$this->context instanceof ExecutionContext) {
         throw new ValidatorException('ConstraintValidator::initialize() must be called before setting violation messages');
     }
     $this->context->addViolation($template, $parameters);
 }
开发者ID:ronnylt,项目名称:symfony,代码行数:15,代码来源:ConstraintValidator.php

示例11: hasCorrectBaseHref

 /**
  * @param string $url referrer url to check against base href of this application
  * @param \Symfony\Component\Validator\ExecutionContextInterface $context
  */
 public function hasCorrectBaseHref($url, ExecutionContextInterface $context)
 {
     if (!is_string($url)) {
         $context->addViolation('URL is not a string.');
     } else {
         $base_href = $this->getContext()->getRouting()->getBaseHref();
         if (strpos($url, "{$base_href}", 0) !== 0) {
             $context->addViolation('URL does not start with base href of this application. Same origin violation.');
         }
     }
 }
开发者ID:honeybee,项目名称:honeybee-agavi-cmf-vendor,代码行数:15,代码来源:RedirectValidator.php

示例12: 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:zorn-v,项目名称:thelia,代码行数:12,代码来源:CountryStateMigrationType.php

示例13: checkEmails

 public function checkEmails($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     $value = trim($value);
     if ("" === trim($value) && !empty($data["enabled"])) {
         $context->addViolation($this->trans("The Emails can not be empty", ["%id" => $value]));
     }
     $emails = explode(',', $value);
     foreach ($emails as $email) {
         if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $context->addViolation($this->trans("'%email' is not a valid email address", ["%email" => $email]));
         }
     }
 }
开发者ID:Mertiozys,项目名称:StockAlert,代码行数:14,代码来源:StockAlertConfig.php

示例14: 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:GuiminZHOU,项目名称:thelia,代码行数:14,代码来源:AdminCreatePassword.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (isset($value)) {
         try {
             /** @var \Drupal\Core\Url $url */
             $url = $value->getUrl();
         } catch (\InvalidArgumentException $e) {
             return;
         }
         // Disallow external URLs using untrusted protocols.
         if ($url->isExternal() && !in_array(parse_url($url->getUri(), PHP_URL_SCHEME), UrlHelper::getAllowedProtocols())) {
             $this->context->addViolation($constraint->message, array('@uri' => $value->uri));
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:18,代码来源:LinkExternalProtocolsConstraintValidator.php


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