You are here

public static function MimeDetectService::checkFileinfo in MimeDetect 8

Checks the availability for PHP fileinfo mime detection engine.

Parameters

string $magic_file: An optional 'magic' information file.

string $msg: Optional string variable reference to place error message.

Return value

bool Test result. TRUE if OK, FALSE on error.

2 calls to MimeDetectService::checkFileinfo()
MimeDetectService::__construct in src/MimeDetectService.php
Construct the MimeDetectService object.
MimeDetectSettingsForm::validateForm in src/Form/MimeDetectSettingsForm.php
Form validation handler.

File

src/MimeDetectService.php, line 174

Class

MimeDetectService
MimeDetect service.

Namespace

Drupal\mimedetect

Code

public static function checkFileinfo($magic_file = '', &$msg = '') {

  // Test magic file if not empty.
  $errors = !empty($magic_file) ? !MimeDetectService::checkMagicfile($magic_file, $msg) : FALSE;
  if ($errors) {
    return FALSE;
  }

  // Check extension availability.
  if ($errors = !extension_loaded('fileinfo')) {
    $msg = t('PHP file information extension not found.');
  }
  elseif ($errors = !@finfo_open(FILEINFO_MIME, $magic_file)) {
    if (!empty($magic_file)) {
      $msg = t('Fileinfo cannot load the configured magic file %path. It could be corrupted. Try another magic file or remove your magic file path settings to use defaults.', [
        '%path' => $magic_file,
      ]);
    }
    else {
      $msg = t('Fileinfo could not load magic information. Check the MAGIC environment variable on your system and that fileinfo PHP extension is properly installed.');
    }
  }
  return !$errors;
}