Final Class Yiisoft\Yii\Gii\Validator\ClassExistsHandler
| Inheritance | Yiisoft\Yii\Gii\Validator\ClassExistsHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
An inline validator that checks if the attribute value refers to an existing class name.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Yii\Gii\Validator\ClassExistsHandler |
Method Details
| public \Yiisoft\Validator\Result validate ( mixed $value, object $rule, \Yiisoft\Validator\ValidationContext $context ) | ||
| $value | mixed | |
| $rule | object | |
| $context | \Yiisoft\Validator\ValidationContext | |
public function validate(mixed $value, object $rule, ValidationContext $context): Result
{
if (!$rule instanceof ClassExistsRule) {
throw new UnexpectedRuleException(ClassExistsRule::class, $rule);
}
$result = new Result();
if (!is_string($value)) {
$result->addError(sprintf('Value must be a string, %s given.".', gettype($value)));
return $result;
}
if (!class_exists($value)) {
$result->addError("Class '$value' does not exist or has syntax error.");
}
return $result;
}
Signup or Login in order to comment.