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;
$value = (string) $value;
$canonical = str_replace('-', '', $value);
- if (null === $constraint->type) {
- if ($constraint->isbn10 && !$constraint->isbn13) {
- @trigger_error('The "isbn10" option of the Isbn constraint is deprecated since version 2.5 and will be removed in 3.0. Use the "type" option instead.', E_USER_DEPRECATED);
- $constraint->type = 'isbn10';
- } elseif ($constraint->isbn13 && !$constraint->isbn10) {
- @trigger_error('The "isbn13" option of the Isbn constraint is deprecated since version 2.5 and will be removed in 3.0. Use the "type" option instead.', E_USER_DEPRECATED);
- $constraint->type = 'isbn13';
- }
- }
-
// Explicitly validate against ISBN-10
if ('isbn10' === $constraint->type) {
if (true !== ($code = $this->validateIsbn10($canonical))) {
- 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();
- }
+ $this->context->buildViolation($this->getMessage($constraint, $constraint->type))
+ ->setParameter('{{ value }}', $this->formatValue($value))
+ ->setCode($code)
+ ->addViolation();
}
return;
// Explicitly validate against ISBN-13
if ('isbn13' === $constraint->type) {
if (true !== ($code = $this->validateIsbn13($canonical))) {
- 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();
- }
+ $this->context->buildViolation($this->getMessage($constraint, $constraint->type))
+ ->setParameter('{{ value }}', $this->formatValue($value))
+ ->setCode($code)
+ ->addViolation();
}
return;
}
if (true !== $code) {
- 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();
- }
+ $this->context->buildViolation($this->getMessage($constraint))
+ ->setParameter('{{ value }}', $this->formatValue($value))
+ ->setCode($code)
+ ->addViolation();
}
}