private function UuidValidator::validateStrict in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/validator/Constraints/UuidValidator.php \Symfony\Component\Validator\Constraints\UuidValidator::validateStrict()
1 call to UuidValidator::validateStrict()
- UuidValidator::validate in vendor/symfony/validator/Constraints/UuidValidator.php
- Checks if the passed value is valid.
File
- vendor/symfony/validator/Constraints/UuidValidator.php, line 198
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])) {
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;
}
if ('-' === $value[$i]) {
if ($i !== $h) {
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;
}
if ($h < self::STRICT_LAST_HYPHEN_POSITION) {
$h += 5;
}
continue;
}
if (!ctype_xdigit($value[$i])) {
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;
}
if ($i === $h) {
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;
}
}
if (isset($value[$i])) {
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();
}
}
if (!in_array($value[self::STRICT_VERSION_POSITION], $constraint->versions)) {
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();
}
}
if ((hexdec($value[self::STRICT_VARIANT_POSITION]) & 12) !== 8) {
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();
}
}
}