private function UuidValidator::validateStrict in Plug 7
1 call to UuidValidator::validateStrict()
- UuidValidator::validate in lib/Symfony/validator/Symfony/Component/Validator/Constraints/UuidValidator.php
- Checks if the passed value is valid.
File
- lib/Symfony/validator/Symfony/Component/Validator/Constraints/UuidValidator.php, line 168
Class
- UuidValidator
- Validates whether the value is a valid UUID per RFC 4122.
Namespace
Symfony\Component\Validator\Constraints
Code
private function validateStrict($value, Uuid $constraint) {
$h = self::STRICT_FIRST_HYPHEN_POSITION;
for ($i = 0; $i < self::STRICT_LENGTH; ++$i) {
if (!isset($value[$i])) {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->setCode(Uuid::TOO_SHORT_ERROR)
->addViolation();
return;
}
if ('-' === $value[$i]) {
if ($i !== $h) {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
->addViolation();
return;
}
if ($h < self::STRICT_LAST_HYPHEN_POSITION) {
$h += 5;
}
continue;
}
if (!ctype_xdigit($value[$i])) {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->setCode(Uuid::INVALID_CHARACTERS_ERROR)
->addViolation();
return;
}
if ($i === $h) {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->setCode(Uuid::INVALID_HYPHEN_PLACEMENT_ERROR)
->addViolation();
return;
}
}
if (isset($value[$i])) {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->setCode(Uuid::TOO_LONG_ERROR)
->addViolation();
}
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 ((hexdec($value[self::STRICT_VARIANT_POSITION]) & 12) !== 8) {
$this
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this
->formatValue($value))
->setCode(Uuid::INVALID_VARIANT_ERROR)
->addViolation();
}
}