[Validator] fixed deprecation notices for BuildViolation() calls in constraints
This commit is contained in:
parent
fb3f9d2d1c
commit
c6f1f69b7a
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bridge\Doctrine\Validator\Constraints;
|
||||
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
@ -133,9 +134,16 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
|
||||
$errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $fields[0];
|
||||
|
||||
$this->buildViolation($constraint->message)
|
||||
->atPath($errorPath)
|
||||
->setInvalidValue($criteria[$fields[0]])
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->atPath($errorPath)
|
||||
->setInvalidValue($criteria[$fields[0]])
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->atPath($errorPath)
|
||||
->setInvalidValue($criteria[$fields[0]])
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,22 +99,39 @@ class FormValidator extends ConstraintValidator
|
||||
? (string) $form->getViewData()
|
||||
: gettype($form->getViewData());
|
||||
|
||||
$this->buildViolation($config->getOption('invalid_message'))
|
||||
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
|
||||
->setInvalidValue($form->getViewData())
|
||||
->setCode(Form::NOT_SYNCHRONIZED_ERROR)
|
||||
->setCause($form->getTransformationFailure())
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($config->getOption('invalid_message'))
|
||||
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
|
||||
->setInvalidValue($form->getViewData())
|
||||
->setCode(Form::NOT_SYNCHRONIZED_ERROR)
|
||||
->setCause($form->getTransformationFailure())
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($config->getOption('invalid_message'))
|
||||
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
|
||||
->setInvalidValue($form->getViewData())
|
||||
->setCode(Form::NOT_SYNCHRONIZED_ERROR)
|
||||
->setCause($form->getTransformationFailure())
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the form with an error if it contains extra fields
|
||||
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
|
||||
$this->buildViolation($config->getOption('extra_fields_message'))
|
||||
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
|
||||
->setInvalidValue($form->getExtraData())
|
||||
->setCode(Form::NO_SUCH_FIELD_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($config->getOption('extra_fields_message'))
|
||||
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
|
||||
->setInvalidValue($form->getExtraData())
|
||||
->setCode(Form::NO_SUCH_FIELD_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($config->getOption('extra_fields_message'))
|
||||
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
|
||||
->setInvalidValue($form->getExtraData())
|
||||
->setCode(Form::NO_SUCH_FIELD_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Core\Validator\Constraints;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -54,11 +55,19 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (!$this->compareValues($value, $comparedValue)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING | self::PRETTY_DATE))
|
||||
->setParameter('{{ compared_value }}', $this->formatValue($comparedValue, self::OBJECT_TO_STRING | self::PRETTY_DATE))
|
||||
->setParameter('{{ compared_value_type }}', $this->formatTypeOf($comparedValue))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING | self::PRETTY_DATE))
|
||||
->setParameter('{{ compared_value }}', $this->formatValue($comparedValue, self::OBJECT_TO_STRING | self::PRETTY_DATE))
|
||||
->setParameter('{{ compared_value_type }}', $this->formatTypeOf($comparedValue))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING | self::PRETTY_DATE))
|
||||
->setParameter('{{ compared_value }}', $this->formatValue($comparedValue, self::OBJECT_TO_STRING | self::PRETTY_DATE))
|
||||
->setParameter('{{ compared_value_type }}', $this->formatTypeOf($comparedValue))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -32,9 +33,15 @@ class BlankValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if ('' !== $value && null !== $value) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -115,10 +116,17 @@ class CardSchemeValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (!is_numeric($value)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(CardScheme::NOT_NUMERIC_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(CardScheme::NOT_NUMERIC_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(CardScheme::NOT_NUMERIC_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -134,9 +142,16 @@ class CardSchemeValidator extends ConstraintValidator
|
||||
}
|
||||
}
|
||||
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(CardScheme::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(CardScheme::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(CardScheme::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
@ -62,11 +63,19 @@ class ChoiceValidator extends ConstraintValidator
|
||||
if ($constraint->multiple) {
|
||||
foreach ($value as $_value) {
|
||||
if (!in_array($_value, $choices, $constraint->strict)) {
|
||||
$this->buildViolation($constraint->multipleMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($_value))
|
||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||
->setInvalidValue($_value)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->multipleMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($_value))
|
||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||
->setInvalidValue($_value)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->multipleMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($_value))
|
||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||
->setInvalidValue($_value)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -75,29 +84,52 @@ class ChoiceValidator extends ConstraintValidator
|
||||
$count = count($value);
|
||||
|
||||
if ($constraint->min !== null && $count < $constraint->min) {
|
||||
$this->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Choice::TOO_FEW_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Choice::TOO_FEW_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Choice::TOO_FEW_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($constraint->max !== null && $count > $constraint->max) {
|
||||
$this->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Choice::TOO_MANY_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Choice::TOO_MANY_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Choice::TOO_MANY_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,12 +69,21 @@ class CollectionValidator extends ConstraintValidator
|
||||
}
|
||||
}
|
||||
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
||||
$this->buildViolationInContext($context, $constraint->missingFieldsMessage)
|
||||
->atPath('['.$field.']')
|
||||
->setParameter('{{ field }}', $this->formatValue($field))
|
||||
->setInvalidValue(null)
|
||||
->setCode(Collection::MISSING_FIELD_ERROR)
|
||||
->addViolation();
|
||||
if ($context instanceof ExecutionContextInterface) {
|
||||
$context->buildViolation($constraint->missingFieldsMessage)
|
||||
->atPath('['.$field.']')
|
||||
->setParameter('{{ field }}', $this->formatValue($field))
|
||||
->setInvalidValue(null)
|
||||
->setCode(Collection::MISSING_FIELD_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolationInContext($context, $constraint->missingFieldsMessage)
|
||||
->atPath('['.$field.']')
|
||||
->setParameter('{{ field }}', $this->formatValue($field))
|
||||
->setInvalidValue(null)
|
||||
->setCode(Collection::MISSING_FIELD_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -36,25 +37,45 @@ class CountValidator extends ConstraintValidator
|
||||
$count = count($value);
|
||||
|
||||
if (null !== $constraint->max && $count > $constraint->max) {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Count::TOO_MANY_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Count::TOO_MANY_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Count::TOO_MANY_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $count < $constraint->min) {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Count::TOO_FEW_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Count::TOO_FEW_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
|
||||
->setParameter('{{ count }}', $count)
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Count::TOO_FEW_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -46,9 +47,15 @@ class CountryValidator extends ConstraintValidator
|
||||
$countries = Intl::getRegionBundle()->getCountryNames();
|
||||
|
||||
if (!isset($countries[$value])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -46,9 +47,15 @@ class CurrencyValidator extends ConstraintValidator
|
||||
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
|
||||
|
||||
if (!isset($currencies[$value])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
@ -43,26 +44,47 @@ class DateTimeValidator extends DateValidator
|
||||
$value = (string) $value;
|
||||
|
||||
if (!preg_match(static::PATTERN, $value, $matches)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DateValidator::checkDate($matches[1], $matches[2], $matches[3])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_DATE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_DATE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_DATE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
if (!TimeValidator::checkTime($matches[4], $matches[5], $matches[6])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_TIME_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_TIME_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(DateTime::INVALID_TIME_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -60,19 +61,33 @@ class DateValidator extends ConstraintValidator
|
||||
$value = (string) $value;
|
||||
|
||||
if (!preg_match(static::PATTERN, $value, $matches)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Date::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Date::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Date::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self::checkDate($matches[1], $matches[2], $matches[3])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Date::INVALID_DATE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Date::INVALID_DATE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Date::INVALID_DATE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\RuntimeException;
|
||||
@ -66,18 +67,32 @@ class EmailValidator extends ConstraintValidator
|
||||
$strictValidator = new \Egulias\EmailValidator\EmailValidator();
|
||||
|
||||
if (!$strictValidator->isValid($value, false, true)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} elseif (!preg_match('/.+\@.+\..+/', $value)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -87,20 +102,34 @@ class EmailValidator extends ConstraintValidator
|
||||
// Check for host DNS resource records
|
||||
if ($constraint->checkMX) {
|
||||
if (!$this->checkMX($host)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::MX_CHECK_FAILED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::MX_CHECK_FAILED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::MX_CHECK_FAILED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($constraint->checkHost && !$this->checkHost($host)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::HOST_CHECK_FAILED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::HOST_CHECK_FAILED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Email::HOST_CHECK_FAILED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,9 +85,15 @@ class ExpressionValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -35,8 +36,14 @@ class FalseValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\File as FileObject;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -63,53 +64,103 @@ class FileValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes(0, $limitInBytes, $binaryFormat);
|
||||
$this->buildViolation($constraint->uploadIniSizeErrorMessage)
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setCode(UPLOAD_ERR_INI_SIZE)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadIniSizeErrorMessage)
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setCode(UPLOAD_ERR_INI_SIZE)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadIniSizeErrorMessage)
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setCode(UPLOAD_ERR_INI_SIZE)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->buildViolation($constraint->uploadFormSizeErrorMessage)
|
||||
->setCode(UPLOAD_ERR_FORM_SIZE)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadFormSizeErrorMessage)
|
||||
->setCode(UPLOAD_ERR_FORM_SIZE)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadFormSizeErrorMessage)
|
||||
->setCode(UPLOAD_ERR_FORM_SIZE)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
$this->buildViolation($constraint->uploadPartialErrorMessage)
|
||||
->setCode(UPLOAD_ERR_PARTIAL)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadPartialErrorMessage)
|
||||
->setCode(UPLOAD_ERR_PARTIAL)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadPartialErrorMessage)
|
||||
->setCode(UPLOAD_ERR_PARTIAL)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$this->buildViolation($constraint->uploadNoFileErrorMessage)
|
||||
->setCode(UPLOAD_ERR_NO_FILE)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadNoFileErrorMessage)
|
||||
->setCode(UPLOAD_ERR_NO_FILE)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadNoFileErrorMessage)
|
||||
->setCode(UPLOAD_ERR_NO_FILE)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->buildViolation($constraint->uploadNoTmpDirErrorMessage)
|
||||
->setCode(UPLOAD_ERR_NO_TMP_DIR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadNoTmpDirErrorMessage)
|
||||
->setCode(UPLOAD_ERR_NO_TMP_DIR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadNoTmpDirErrorMessage)
|
||||
->setCode(UPLOAD_ERR_NO_TMP_DIR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
$this->buildViolation($constraint->uploadCantWriteErrorMessage)
|
||||
->setCode(UPLOAD_ERR_CANT_WRITE)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadCantWriteErrorMessage)
|
||||
->setCode(UPLOAD_ERR_CANT_WRITE)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadCantWriteErrorMessage)
|
||||
->setCode(UPLOAD_ERR_CANT_WRITE)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
$this->buildViolation($constraint->uploadExtensionErrorMessage)
|
||||
->setCode(UPLOAD_ERR_EXTENSION)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadExtensionErrorMessage)
|
||||
->setCode(UPLOAD_ERR_EXTENSION)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadExtensionErrorMessage)
|
||||
->setCode(UPLOAD_ERR_EXTENSION)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
default:
|
||||
$this->buildViolation($constraint->uploadErrorMessage)
|
||||
->setCode($value->getError())
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->uploadErrorMessage)
|
||||
->setCode($value->getError())
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->uploadErrorMessage)
|
||||
->setCode($value->getError())
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -122,19 +173,33 @@ class FileValidator extends ConstraintValidator
|
||||
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
|
||||
|
||||
if (!is_file($path)) {
|
||||
$this->buildViolation($constraint->notFoundMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::NOT_FOUND_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->notFoundMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::NOT_FOUND_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->notFoundMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::NOT_FOUND_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_readable($path)) {
|
||||
$this->buildViolation($constraint->notReadableMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::NOT_READABLE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->notReadableMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::NOT_READABLE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->notReadableMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::NOT_READABLE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -142,10 +207,17 @@ class FileValidator extends ConstraintValidator
|
||||
$sizeInBytes = filesize($path);
|
||||
|
||||
if (0 === $sizeInBytes) {
|
||||
$this->buildViolation($constraint->disallowEmptyMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::EMPTY_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->disallowEmptyMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::EMPTY_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->disallowEmptyMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setCode(File::EMPTY_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -155,13 +227,23 @@ class FileValidator extends ConstraintValidator
|
||||
|
||||
if ($sizeInBytes > $limitInBytes) {
|
||||
list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes($sizeInBytes, $limitInBytes, $constraint->binaryFormat);
|
||||
$this->buildViolation($constraint->maxSizeMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setParameter('{{ size }}', $sizeAsString)
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setCode(File::TOO_LARGE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->maxSizeMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setParameter('{{ size }}', $sizeAsString)
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setCode(File::TOO_LARGE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->maxSizeMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setParameter('{{ size }}', $sizeAsString)
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setCode(File::TOO_LARGE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -187,12 +269,21 @@ class FileValidator extends ConstraintValidator
|
||||
}
|
||||
}
|
||||
|
||||
$this->buildViolation($constraint->mimeTypesMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setParameter('{{ type }}', $this->formatValue($mime))
|
||||
->setParameter('{{ types }}', $this->formatValues($mimeTypes))
|
||||
->setCode(File::INVALID_MIME_TYPE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->mimeTypesMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setParameter('{{ type }}', $this->formatValue($mime))
|
||||
->setParameter('{{ types }}', $this->formatValues($mimeTypes))
|
||||
->setCode(File::INVALID_MIME_TYPE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->mimeTypesMessage)
|
||||
->setParameter('{{ file }}', $this->formatValue($path))
|
||||
->setParameter('{{ type }}', $this->formatValue($mime))
|
||||
->setParameter('{{ types }}', $this->formatValues($mimeTypes))
|
||||
->setCode(File::INVALID_MIME_TYPE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -48,40 +49,68 @@ class IbanValidator extends ConstraintValidator
|
||||
|
||||
// The IBAN must have at least 4 characters...
|
||||
if (strlen($canonicalized) < 4) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ...start with a country code...
|
||||
if (!ctype_alpha($canonicalized{0}) || !ctype_alpha($canonicalized{1})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_COUNTRY_CODE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_COUNTRY_CODE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_COUNTRY_CODE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ...contain only digits and characters...
|
||||
if (!ctype_alnum($canonicalized)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ...and contain uppercase characters only
|
||||
if ($canonicalized !== strtoupper($canonicalized)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_CASE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_CASE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::INVALID_CASE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -102,10 +131,17 @@ class IbanValidator extends ConstraintValidator
|
||||
// We cannot use PHP's modulo operator, so we calculate the
|
||||
// modulo step-wisely instead
|
||||
if (1 !== $this->bigModulo97($checkSum)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Iban::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -53,9 +54,15 @@ class ImageValidator extends FileValidator
|
||||
$size = @getimagesize($value);
|
||||
|
||||
if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
|
||||
$this->buildViolation($constraint->sizeNotDetectedMessage)
|
||||
->setCode(Image::SIZE_NOT_DETECTED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->sizeNotDetectedMessage)
|
||||
->setCode(Image::SIZE_NOT_DETECTED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->sizeNotDetectedMessage)
|
||||
->setCode(Image::SIZE_NOT_DETECTED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -69,11 +76,19 @@ class ImageValidator extends FileValidator
|
||||
}
|
||||
|
||||
if ($width < $constraint->minWidth) {
|
||||
$this->buildViolation($constraint->minWidthMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ min_width }}', $constraint->minWidth)
|
||||
->setCode(Image::TOO_NARROW_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->minWidthMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ min_width }}', $constraint->minWidth)
|
||||
->setCode(Image::TOO_NARROW_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->minWidthMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ min_width }}', $constraint->minWidth)
|
||||
->setCode(Image::TOO_NARROW_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -85,11 +100,19 @@ class ImageValidator extends FileValidator
|
||||
}
|
||||
|
||||
if ($width > $constraint->maxWidth) {
|
||||
$this->buildViolation($constraint->maxWidthMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ max_width }}', $constraint->maxWidth)
|
||||
->setCode(Image::TOO_WIDE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->maxWidthMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ max_width }}', $constraint->maxWidth)
|
||||
->setCode(Image::TOO_WIDE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->maxWidthMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ max_width }}', $constraint->maxWidth)
|
||||
->setCode(Image::TOO_WIDE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -101,11 +124,19 @@ class ImageValidator extends FileValidator
|
||||
}
|
||||
|
||||
if ($height < $constraint->minHeight) {
|
||||
$this->buildViolation($constraint->minHeightMessage)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setParameter('{{ min_height }}', $constraint->minHeight)
|
||||
->setCode(Image::TOO_LOW_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->minHeightMessage)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setParameter('{{ min_height }}', $constraint->minHeight)
|
||||
->setCode(Image::TOO_LOW_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->minHeightMessage)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setParameter('{{ min_height }}', $constraint->minHeight)
|
||||
->setCode(Image::TOO_LOW_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -117,11 +148,19 @@ class ImageValidator extends FileValidator
|
||||
}
|
||||
|
||||
if ($height > $constraint->maxHeight) {
|
||||
$this->buildViolation($constraint->maxHeightMessage)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setParameter('{{ max_height }}', $constraint->maxHeight)
|
||||
->setCode(Image::TOO_HIGH_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->maxHeightMessage)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setParameter('{{ max_height }}', $constraint->maxHeight)
|
||||
->setCode(Image::TOO_HIGH_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->maxHeightMessage)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setParameter('{{ max_height }}', $constraint->maxHeight)
|
||||
->setCode(Image::TOO_HIGH_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,11 +172,19 @@ class ImageValidator extends FileValidator
|
||||
}
|
||||
|
||||
if ($ratio < $constraint->minRatio) {
|
||||
$this->buildViolation($constraint->minRatioMessage)
|
||||
->setParameter('{{ ratio }}', $ratio)
|
||||
->setParameter('{{ min_ratio }}', $constraint->minRatio)
|
||||
->setCode(Image::RATIO_TOO_SMALL_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->minRatioMessage)
|
||||
->setParameter('{{ ratio }}', $ratio)
|
||||
->setParameter('{{ min_ratio }}', $constraint->minRatio)
|
||||
->setCode(Image::RATIO_TOO_SMALL_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->minRatioMessage)
|
||||
->setParameter('{{ ratio }}', $ratio)
|
||||
->setParameter('{{ min_ratio }}', $constraint->minRatio)
|
||||
->setCode(Image::RATIO_TOO_SMALL_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,36 +194,68 @@ class ImageValidator extends FileValidator
|
||||
}
|
||||
|
||||
if ($ratio > $constraint->maxRatio) {
|
||||
$this->buildViolation($constraint->maxRatioMessage)
|
||||
->setParameter('{{ ratio }}', $ratio)
|
||||
->setParameter('{{ max_ratio }}', $constraint->maxRatio)
|
||||
->setCode(Image::RATIO_TOO_BIG_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->maxRatioMessage)
|
||||
->setParameter('{{ ratio }}', $ratio)
|
||||
->setParameter('{{ max_ratio }}', $constraint->maxRatio)
|
||||
->setCode(Image::RATIO_TOO_BIG_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->maxRatioMessage)
|
||||
->setParameter('{{ ratio }}', $ratio)
|
||||
->setParameter('{{ max_ratio }}', $constraint->maxRatio)
|
||||
->setCode(Image::RATIO_TOO_BIG_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$constraint->allowSquare && $width == $height) {
|
||||
$this->buildViolation($constraint->allowSquareMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::SQUARE_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->allowSquareMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::SQUARE_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->allowSquareMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::SQUARE_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$constraint->allowLandscape && $width > $height) {
|
||||
$this->buildViolation($constraint->allowLandscapeMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::LANDSCAPE_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->allowLandscapeMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::LANDSCAPE_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->allowLandscapeMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::LANDSCAPE_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$constraint->allowPortrait && $width < $height) {
|
||||
$this->buildViolation($constraint->allowPortraitMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->allowPortraitMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->allowPortraitMessage)
|
||||
->setParameter('{{ width }}', $width)
|
||||
->setParameter('{{ height }}', $height)
|
||||
->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -95,9 +96,16 @@ class IpValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -59,10 +60,17 @@ class IsbnValidator extends ConstraintValidator
|
||||
// Explicitly validate against ISBN-10
|
||||
if ('isbn10' === $constraint->type) {
|
||||
if (true !== ($code = $this->validateIsbn10($canonical))) {
|
||||
$this->buildViolation($this->getMessage($constraint, $constraint->type))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($this->getMessage($constraint, $constraint->type))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($this->getMessage($constraint, $constraint->type))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@ -71,10 +79,17 @@ class IsbnValidator extends ConstraintValidator
|
||||
// Explicitly validate against ISBN-13
|
||||
if ('isbn13' === $constraint->type) {
|
||||
if (true !== ($code = $this->validateIsbn13($canonical))) {
|
||||
$this->buildViolation($this->getMessage($constraint, $constraint->type))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($this->getMessage($constraint, $constraint->type))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($this->getMessage($constraint, $constraint->type))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@ -97,10 +112,17 @@ class IsbnValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (true !== $code) {
|
||||
$this->buildViolation($this->getMessage($constraint))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($this->getMessage($constraint))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($this->getMessage($constraint))
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode($code)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -51,10 +52,17 @@ class IssnValidator extends ConstraintValidator
|
||||
// remove hyphen
|
||||
$canonical = substr($canonical, 0, 4).substr($canonical, 5);
|
||||
} elseif ($constraint->requireHyphen) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::MISSING_HYPHEN_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::MISSING_HYPHEN_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::MISSING_HYPHEN_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -62,19 +70,33 @@ class IssnValidator extends ConstraintValidator
|
||||
$length = strlen($canonical);
|
||||
|
||||
if ($length < 8) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($length > 8) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -82,10 +104,17 @@ class IssnValidator extends ConstraintValidator
|
||||
// 1234567X
|
||||
// ^^^^^^^ digits only
|
||||
if (!ctype_digit(substr($canonical, 0, 7))) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -93,10 +122,17 @@ class IssnValidator extends ConstraintValidator
|
||||
// 1234567X
|
||||
// ^ digit, x or X
|
||||
if (!ctype_digit($canonical{7}) && 'x' !== $canonical{7} && 'X' !== $canonical{7}) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -104,10 +140,17 @@ class IssnValidator extends ConstraintValidator
|
||||
// 1234567X
|
||||
// ^ case-sensitive?
|
||||
if ($constraint->caseSensitive && 'x' === $canonical{7}) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CASE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CASE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::INVALID_CASE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -123,10 +166,17 @@ class IssnValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (0 !== $checkSum % 11) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Issn::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -46,9 +47,15 @@ class LanguageValidator extends ConstraintValidator
|
||||
$languages = Intl::getLanguageBundle()->getLanguageNames();
|
||||
|
||||
if (!isset($languages[$value])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -48,25 +49,45 @@ class LengthValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (null !== $constraint->max && $length > $constraint->max) {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Length::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Length::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||
->setParameter('{{ limit }}', $constraint->max)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->max)
|
||||
->setCode(Length::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $length < $constraint->min) {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Length::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Length::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||
->setParameter('{{ limit }}', $constraint->min)
|
||||
->setInvalidValue($value)
|
||||
->setPlural((int) $constraint->min)
|
||||
->setCode(Length::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -46,9 +47,15 @@ class LocaleValidator extends ConstraintValidator
|
||||
$locales = Intl::getLocaleBundle()->getLocaleNames();
|
||||
|
||||
if (!isset($locales[$value])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -56,10 +57,17 @@ class LuhnValidator extends ConstraintValidator
|
||||
$value = (string) $value;
|
||||
|
||||
if (!ctype_digit($value)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Luhn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Luhn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Luhn::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -87,10 +95,17 @@ class LuhnValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (0 === $checkSum || 0 !== $checkSum % 10) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Luhn::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Luhn::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Luhn::CHECKSUM_FAILED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -32,9 +33,15 @@ class NotBlankValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (false === $value || (empty($value) && '0' != $value)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -32,9 +33,15 @@ class NullValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (null !== $value) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -34,10 +35,17 @@ class RangeValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (!is_numeric($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
$this->buildViolation($constraint->invalidMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setCode(Range::INVALID_VALUE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->invalidMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setCode(Range::INVALID_VALUE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->invalidMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setCode(Range::INVALID_VALUE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -60,21 +68,37 @@ class RangeValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (null !== $constraint->max && $value > $max) {
|
||||
$this->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE))
|
||||
->setCode(Range::BEYOND_RANGE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE))
|
||||
->setCode(Range::BEYOND_RANGE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->maxMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE))
|
||||
->setCode(Range::BEYOND_RANGE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $constraint->min && $value < $min) {
|
||||
$this->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE))
|
||||
->setCode(Range::BELOW_RANGE_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE))
|
||||
->setCode(Range::BELOW_RANGE_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->minMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE))
|
||||
->setCode(Range::BELOW_RANGE_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -45,9 +46,15 @@ class RegexValidator extends ConstraintValidator
|
||||
$value = (string) $value;
|
||||
|
||||
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -60,19 +61,33 @@ class TimeValidator extends ConstraintValidator
|
||||
$value = (string) $value;
|
||||
|
||||
if (!preg_match(static::PATTERN, $value, $matches)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Time::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Time::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Time::INVALID_FORMAT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self::checkTime($matches[1], $matches[2], $matches[3])) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Time::INVALID_TIME_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Time::INVALID_TIME_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Time::INVALID_TIME_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -36,9 +37,15 @@ class TrueValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
if (true !== $value && 1 !== $value && '1' !== $value) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -48,9 +49,16 @@ class TypeValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setParameter('{{ type }}', $constraint->type)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setParameter('{{ type }}', $constraint->type)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setParameter('{{ type }}', $constraint->type)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -59,9 +60,15 @@ class UrlValidator extends ConstraintValidator
|
||||
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
|
||||
|
||||
if (!preg_match($pattern, $value)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -70,9 +77,15 @@ class UrlValidator extends ConstraintValidator
|
||||
$host = parse_url($value, PHP_URL_HOST);
|
||||
|
||||
if (!checkdnsrr($host, 'ANY')) {
|
||||
$this->buildViolation($constraint->dnsMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($host))
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->dnsMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($host))
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->dnsMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($host))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Constraints\Deprecated\UuidValidator as Deprecated;
|
||||
@ -114,10 +115,17 @@ class UuidValidator extends ConstraintValidator
|
||||
for ($i = 0; $i < $l; ++$i) {
|
||||
// Check length
|
||||
if (!isset($trimmed{$i})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -127,10 +135,17 @@ class UuidValidator extends ConstraintValidator
|
||||
// ^ ^ ^ ^ ^ ^ ^
|
||||
if ('-' === $trimmed{$i}) {
|
||||
if ($i !== $h) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -148,10 +163,17 @@ class UuidValidator extends ConstraintValidator
|
||||
|
||||
// Check characters
|
||||
if (!ctype_xdigit($trimmed{$i})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -159,10 +181,17 @@ class UuidValidator extends ConstraintValidator
|
||||
|
||||
// Check length again
|
||||
if (isset($trimmed{$i})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,10 +210,17 @@ class UuidValidator extends ConstraintValidator
|
||||
for ($i = 0; $i < self::STRICT_LENGTH; ++$i) {
|
||||
// Check length
|
||||
if (!isset($value{$i})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_SHORT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -194,13 +230,23 @@ class UuidValidator extends ConstraintValidator
|
||||
// ^ ^ ^ ^
|
||||
if ('-' === $value{$i}) {
|
||||
if ($i !== $h) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter(
|
||||
'{{ value }}',
|
||||
$this->formatValue($value)
|
||||
)
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter(
|
||||
'{{ value }}',
|
||||
$this->formatValue($value)
|
||||
)
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter(
|
||||
'{{ value }}',
|
||||
$this->formatValue($value)
|
||||
)
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -216,20 +262,34 @@ class UuidValidator extends ConstraintValidator
|
||||
|
||||
// Check characters
|
||||
if (!ctype_xdigit($value{$i})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Missing hyphen
|
||||
if ($i === $h) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -237,18 +297,32 @@ class UuidValidator extends ConstraintValidator
|
||||
|
||||
// Check length again
|
||||
if (isset($value{$i})) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::TOO_LONG_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
// Check version
|
||||
if (!in_array($value{self::STRICT_VERSION_POSITION}, $constraint->versions)) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_VERSION_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_VERSION_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_VERSION_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
// Check variant - first two bits must equal "10"
|
||||
@ -256,10 +330,17 @@ class UuidValidator extends ConstraintValidator
|
||||
// & 0b1100 (12)
|
||||
// = 0b1000 (8)
|
||||
if ((hexdec($value{self::STRICT_VARIANT_POSITION}) & 12) !== 8) {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_VARIANT_ERROR)
|
||||
->addViolation();
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_VARIANT_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setCode(Uuid::INVALID_VARIANT_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user