0 follower

Final Class Yiisoft\Yii\Gii\Validator\ClassExistsHandler

InheritanceYiisoft\Yii\Gii\Validator\ClassExistsHandler
ImplementsYiisoft\Validator\RuleHandlerInterface

An inline validator that checks if the attribute value refers to an existing class name.

Method Details

Hide inherited methods

validate() public method

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;
}