function UriHostConstraintValidator::validate

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UriHostConstraintValidator.php, line 19

Class

UriHostConstraintValidator
Validates if a string conforms to the RFC 3986 host component.

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) : void {
    assert($constraint instanceof UriHostConstraint);
    if ($value === NULL || $value === '') {
        return;
    }
    if (!is_string($value)) {
        throw new UnexpectedTypeException($value, 'string');
    }
    if (!$this->isValid($value)) {
        $this->context
            ->addViolation($constraint->message);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.