You are here

public function CdnStreamWrapperConstraintValidator::validate in CDN 8.3

File

src/Plugin/Validation/Constraint/CdnStreamWrapperConstraintValidator.php, line 19

Class

CdnStreamWrapperConstraintValidator
CDN-supported stream wrapper constraint validator.

Namespace

Drupal\cdn\Plugin\Validation\Constraint

Code

public function validate($stream_wrapper, Constraint $constraint) {
  if (!$constraint instanceof CdnStreamWrapperConstraint) {
    throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\CdnStreamWrapper');
  }
  if ($stream_wrapper === NULL) {
    return;
  }
  if (!static::isValidCdnStreamWrapper($stream_wrapper)) {
    $this->context
      ->buildViolation($constraint->message)
      ->setParameter('%stream_wrapper', $stream_wrapper)
      ->setInvalidValue($stream_wrapper)
      ->addViolation();
  }
}