private function UuidValidator::validateLoose in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/validator/Constraints/UuidValidator.php \Symfony\Component\Validator\Constraints\UuidValidator::validateLoose()
1 call to UuidValidator::validateLoose()
- UuidValidator::validate in vendor/symfony/validator/Constraints/UuidValidator.php
- Checks if the passed value is valid.
File
- vendor/symfony/validator/Constraints/UuidValidator.php, line 99
Class
- UuidValidator
- Validates whether the value is a valid UUID per RFC 4122.
Namespace
Symfony\Component\Validator\Constraints
Code
private function validateLoose($value, Uuid $constraint) {
$trimmed = trim($value, '[]{}');
$h = self::LOOSE_FIRST_HYPHEN_POSITION;
$l = self::LOOSE_MAX_LENGTH;
for ($i = 0; $i < $l; ++$i) {
if (!isset($trimmed[$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 ('-' === $trimmed[$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;
}
$h += 5;
continue;
}
if ($i === $h) {
$h += 4;
--$l;
}
if (!ctype_xdigit($trimmed[$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 (isset($trimmed[$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();
}
}
}