Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. IsinValidator.php

function IsinValidator::validate

Overrides ConstraintValidatorInterface::validate

File

vendor/symfony/validator/Constraints/IsinValidator.php, line 26

Class

IsinValidator
@author Laurent Masforné <l.masforne@gmail.com>

Namespace

Symfony\Component\Validator\Constraints

Code

public function validate(mixed $value, Constraint $constraint) : void {
    if (!$constraint instanceof Isin) {
        throw new UnexpectedTypeException($constraint, Isin::class);
    }
    if (null === $value || '' === $value) {
        return;
    }
    if (!\is_scalar($value) && !$value instanceof \Stringable) {
        throw new UnexpectedValueException($value, 'string');
    }
    $value = strtoupper($value);
    if (Isin::VALIDATION_LENGTH !== \strlen($value)) {
        $this->context
            ->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->setCode(Isin::INVALID_LENGTH_ERROR)
            ->addViolation();
        return;
    }
    if (!preg_match(Isin::VALIDATION_PATTERN, $value)) {
        $this->context
            ->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->setCode(Isin::INVALID_PATTERN_ERROR)
            ->addViolation();
        return;
    }
    if (!$this->isCorrectChecksum($value)) {
        $this->context
            ->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->setCode(Isin::INVALID_CHECKSUM_ERROR)
            ->addViolation();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal