function FileEncodingConstraintValidator::validateEncoding

Validates the encoding of the file.

Parameters

string $data: The file data.

string $encoding: The encoding to validate.

\Drupal\file\Plugin\Validation\Constraint\FileEncodingConstraint $constraint: The constraint.

1 call to FileEncodingConstraintValidator::validateEncoding()
FileEncodingConstraintValidator::validate in core/modules/file/src/Plugin/Validation/Constraint/FileEncodingConstraintValidator.php

File

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

Class

FileEncodingConstraintValidator
Validates the file encoding constraint.

Namespace

Drupal\file\Plugin\Validation\Constraint

Code

protected function validateEncoding(string $data, string $encoding, FileEncodingConstraint $constraint) : void {
    if (mb_check_encoding($data, $encoding)) {
        return;
    }
    $this->context
        ->addViolation($constraint->message, [
        '%encoding' => $encoding,
        '%detected' => mb_detect_encoding($data),
    ]);
}

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