public static function FileValidator::validateFileExtension in Mini site 8
Validate that file has one of the provided extensions.
Parameters
string $filename: The filename to validate.
array $extensions: Array of extensions to validate.
Throws
\Drupal\minisite\Exception\InvalidExtensionValidatorException If filename does not have a valid extension from provided list.
4 calls to FileValidator::validateFileExtension()
- ArchiveValidator::validate in src/
ArchiveValidator.php - Validate files.
- Asset::isDocument in src/
Asset.php - Check if asset is a document and can be served as a page.
- FileValidatorTest::testValidateFileExtension in tests/
src/ Unit/ FileValidatorTest.php - Test validateFileExtension() method.
- Minisite::validateArchive in src/
Minisite.php - Validate archive.
File
- src/
FileValidator.php, line 27
Class
- FileValidator
- Class FileValidator.
Namespace
Drupal\minisiteCode
public static function validateFileExtension($filename, array $extensions) {
if (empty($extensions)) {
return;
}
// Ignore folders.
if (substr($filename, -1) == '/') {
return;
}
$regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote(implode(' ', $extensions))) . ')$/i';
if (!preg_match($regex, $filename)) {
throw new InvalidExtensionValidatorException($filename);
}
}