本文整理汇总了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);
}
示例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();
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
}
示例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);
}
}
}