Final Class Yiisoft\Validator\Rule\UuidHandler
| Inheritance | Yiisoft\Validator\Rule\UuidHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
Validates that a value is a proper UUID string.
See also Yiisoft\Validator\Rule\Uuid.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Validator\Rule\UuidHandler |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| PATTERN | '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i' | Yiisoft\Validator\Rule\UuidHandler |
Method Details
| public Yiisoft\Validator\Result validate ( mixed $value, Yiisoft\Validator\RuleInterface $rule, Yiisoft\Validator\ValidationContext $context ) | ||
| $value | mixed | |
| $rule | Yiisoft\Validator\RuleInterface | |
| $context | Yiisoft\Validator\ValidationContext | |
public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
{
if (!$rule instanceof Uuid) {
throw new UnexpectedRuleException(Uuid::class, $rule);
}
$result = new Result();
if (!is_string($value)) {
return $result->addError($rule->getIncorrectInputMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($value),
]);
}
if (!preg_match(self::PATTERN, $value)) {
return $result->addError($rule->getMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'value' => $value,
]);
}
return $result;
}
Signup or Login in order to comment.