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


PHP ExecutionContextInterface::buildViolation方法代码示例

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


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

示例1: buildViolationInContext

 /**
  * Wrapper for {@link ExecutionContextInterface::buildViolation} that
  * supports the 2.4 context API.
  *
  * @param ExecutionContextInterface $context    The context to use
  * @param string                    $message    The violation message
  * @param array                     $parameters The message parameters
  *
  * @return ConstraintViolationBuilderInterface The violation builder
  *
  * @deprecated This method will be removed in Symfony 3.0.
  */
 protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array())
 {
     if ($context instanceof ExecutionContextInterface2Dot5) {
         return $context->buildViolation($message, $parameters);
     }
     return new LegacyConstraintViolationBuilder($context, $message, $parameters);
 }
开发者ID:carlostopo,项目名称:prueba_runator,代码行数:19,代码来源:ConstraintValidator.php

示例2: validateSlug

 public function validateSlug($blog, ExecutionContextInterface $context)
 {
     $unique = $this->getDoctrineRepo('AppBundle:Blog')->isSlugUnique($blog->getSlug(), $blog->getId());
     if (!$unique) {
         $context->buildViolation('The slug is not unique')->addViolation();
     }
 }
开发者ID:artur-dante,项目名称:heyrentme,代码行数:7,代码来源:BlogController.php

示例3: buildViolationInContext

 /**
  * Wrapper for {@link ExecutionContextInterface::buildViolation} that
  * supports the 2.4 context API.
  *
  * @param ExecutionContextInterface $context    The context to use
  * @param string                    $message    The violation message
  * @param array                     $parameters The message parameters
  *
  * @return ConstraintViolationBuilderInterface The violation builder
  *
  * @deprecated since version 2.5, to be removed in 3.0.
  */
 protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array())
 {
     @trigger_error('The ' . __METHOD__ . ' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
     if ($context instanceof ExecutionContextInterface2Dot5) {
         return $context->buildViolation($message, $parameters);
     }
     return new LegacyConstraintViolationBuilder($context, $message, $parameters);
 }
开发者ID:Aryellix,项目名称:scrumator,代码行数:20,代码来源:ConstraintValidator.php

示例4: addViolation

 /**
  * @param string|array $message
  * @param array        $parameters
  * @param null         $value
  *
  * @return ErrorElement
  */
 public function addViolation($message, $parameters = array(), $value = null)
 {
     if (is_array($message)) {
         $value = isset($message[2]) ? $message[2] : $value;
         $parameters = isset($message[1]) ? (array) $message[1] : array();
         $message = isset($message[0]) ? $message[0] : 'error';
     }
     $subPath = (string) $this->getCurrentPropertyPath();
     if ($this->context instanceof LegacyExecutionContextInterface) {
         $this->context->addViolationAt($subPath, $message, $parameters, $value);
     } else {
         $this->context->buildViolation($message)->atPath($subPath)->setParameters($parameters)->setInvalidValue($value)->addViolation();
     }
     $this->errors[] = array($message, $parameters, $value);
     return $this;
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:23,代码来源:ErrorElement.php

示例5: validate

 /**
  * @Assert\Callback
  *
  * @param ExecutionContextInterface $context
  */
 public function validate(ExecutionContextInterface $context)
 {
     $ccn = $this->getCreditCardNumberPlain();
     $ti = $this->typeInfo[$this->getType()];
     if (!preg_match('/' . $ti[0] . '/', $ccn, $match)) {
         $context->buildViolation('Card number not matched with his type.')->atPath('creditCardNumberPlain')->addViolation();
     }
     $isValidLength = false;
     $maxLengths = explode('|', $ti[1]);
     foreach ($maxLengths as $len) {
         if ($len == strlen($ccn)) {
             $isValidLength = true;
             break;
         }
     }
     if (!$isValidLength) {
         $context->buildViolation('Invalid card number length.')->atPath('creditCardNumberPlain')->addViolation();
     }
 }
开发者ID:symfony-devs,项目名称:symfony-dev-tc-bundle,代码行数:24,代码来源:PaymentInfo.php

示例6: validateDiscountCode

 public function validateDiscountCode($data, ExecutionContextInterface $context)
 {
     if (empty($data['discountCode'])) {
         return;
     }
     $dcode = $this->getDoctrineRepo('AppBundle:DiscountCode')->findOneByCode($data['discountCode']);
     if ($dcode === null || $dcode->getStatus() != DiscountCode::STATUS_ASSIGNED) {
         $context->buildViolation('This is not a valid discount code')->atPath('discountCode')->addViolation();
         return;
     }
     $inq = $this->getDoctrineRepo('AppBundle:TalentInquiry')->findOneByUuid($data['uuid']);
     $user = $inq->getUser();
     if ($user === null || $user->getId() !== $dcode->getUser()->getId()) {
         $context->buildViolation('This is not a valid discount code')->atPath('discountCode')->addViolation();
     }
 }
开发者ID:gitroberto,项目名称:heyrentme,代码行数:16,代码来源:TalentBookingController.php

示例7: validate

 /**
  * @Assert\Callback
  */
 public function validate(ExecutionContextInterface $context)
 {
     if ($this->title != ucfirst($this->title)) {
         $context->buildViolation("Le titre {{ value }} doit commencer en majuscule !")->atPath("title")->setParameter("{{ value }}", $this->title)->addViolation();
     }
 }
开发者ID:abdcam,项目名称:symfony3wa,代码行数:9,代码来源:Category.php

示例8: validate

 /**
  * @Assert\Callback
  */
 public function validate(ExecutionContextInterface $context)
 {
     if ($this->pseudo == "admin" && $this->password == "admin") {
         $context->buildViolation("Attention votre speudo ou mot de pass: {{ value }} n'est pas accepté")->atPath("pseudo")->setParameter("{{ value }}", $this->pseudo)->addViolation();
     } elseif ($this->pseudo == "admin" || $this->password == "admin") {
         $context->buildViolation("Cet mot {{ value }}  ne doit pas etre votre speudo!")->atPath("pseudo")->setParameter("{{ value }}", $this->pseudo)->addViolation();
     }
 }
开发者ID:abdcam,项目名称:symfony3wa,代码行数:11,代码来源:User.php

示例9: validateReason

 public function validateReason($talent, ExecutionContextInterface $context)
 {
     if ($this->formHelper != null) {
         $status = $this->formHelper['status']->getData();
         $reason = $this->formHelper['reason']->getData();
         if ($status == Talent::STATUS_REJECTED && ($reason == null || $reason == "")) {
             $context->buildViolation('You have to enter rejection reason.')->addViolation();
         }
     }
 }
开发者ID:gitroberto,项目名称:heyrentme,代码行数:10,代码来源:TalentController.php

示例10: isStatusErroneous

 /**
  * @param ExecutionContextInterface|LegacyExecutionContextInterface $context
  */
 public function isStatusErroneous($context)
 {
     if ($this->getBinaryContent() && $this->getProviderStatus() == self::STATUS_ERROR) {
         // Interface compatibility, the new ExecutionContextInterface should be typehinted when support for Symfony <2.5 is dropped
         if (!$context instanceof ExecutionContextInterface && !$context instanceof LegacyExecutionContextInterface) {
             throw new \InvalidArgumentException('Argument 1 should be an instance of Symfony\\Component\\Validator\\ExecutionContextInterface or Symfony\\Component\\Validator\\Context\\ExecutionContextInterface');
         }
         if ($context instanceof LegacyExecutionContextInterface) {
             $context->addViolationAt('binaryContent', 'invalid', array(), null);
         } else {
             $context->buildViolation('invalid')->atPath('binaryContent')->addViolation();
         }
     }
 }
开发者ID:sidz,项目名称:SonataMediaBundle,代码行数:17,代码来源:Media.php

示例11: isChoixValid

 /**
  * @Assert\Callback
  */
 public function isChoixValid(ExecutionContextInterface $context)
 {
     // valide si les choix ne sont pas le même jour
     $aJours = array();
     foreach ($this->choix as $c) {
         $aJours[] = $c->getActivite()->getJour();
     }
     $aJours = array_unique($aJours);
     if (count($aJours) != count($this->choix)) {
         $context->buildViolation('choix.joursidentiques')->atPath('choix')->addViolation();
     }
 }
开发者ID:lfiduras,项目名称:periscolaire,代码行数:15,代码来源:Eleve.php

示例12: isVoteValid

 /**
  * {@inheritdoc}
  */
 public function isVoteValid(ExecutionContextInterface $context)
 {
     if (!$this->checkValue($this->value)) {
         $message = 'A vote cannot have a 0 value';
         $propertyPath = $context->getPropertyPath() . '.value';
         if ($context instanceof \Symfony\Component\Validator\Context\ExecutionContextInterface) {
             // Validator 2.5 API
             $context->buildViolation($message)->atPath($propertyPath)->addViolation();
         } else {
             $context->addViolationAt($propertyPath, $message);
         }
     }
 }
开发者ID:NonoXyde,项目名称:FOSCommentBundle,代码行数:16,代码来源:Vote.php


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