function FileEncodingConstraintValidator::validate

File

core/modules/file/src/Plugin/Validation/Constraint/FileEncodingConstraintValidator.php, line 18

Class

FileEncodingConstraintValidator
Validates the file encoding constraint.

Namespace

Drupal\file\Plugin\Validation\Constraint

Code

public function validate(mixed $value, Constraint $constraint) : void {
    
    /** @var \Drupal\file\Entity\FileInterface $file */
    $file = $this->assertValueIsFile($value);
    if (!$constraint instanceof FileEncodingConstraint) {
        throw new UnexpectedTypeException($constraint, FileEncodingConstraint::class);
    }
    $encodings = $constraint->encodings;
    $data = file_get_contents($file->getFileUri());
    foreach ($encodings as $encoding) {
        $this->validateEncoding($data, $encoding, $constraint);
    }
}

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