mimedetect.install in MimeDetect 8
Same filename and directory in other branches
Install, update, and uninstall functions for the MimeDetect module.
File
mimedetect.installView source
<?php
/**
* @file
* Install, update, and uninstall functions for the MimeDetect module.
*/
/**
* Implements hook_requirements().
*/
function mimedetect_requirements($phase) {
if ($phase != 'runtime') {
return [];
}
$requirement = [
'title' => t('MIME type enabled detection engines'),
'description' => '',
'severity' => REQUIREMENT_OK,
];
$msg = '';
$config = \Drupal::config('mimedetect.settings');
$mimedetect_service = \Drupal::service('mimedetect');
$magic_file = $config
->get('magicfile');
// Test PHP fileinfo engine.
if (($fileinfo_enabled = $config
->get('fileinfo.enable')) && !$mimedetect_service
->checkFileinfo($magic_file, $msg)) {
$requirement['description'] = $msg . ' ' . t('Fileinfo detection engine cannot be enabled.') . ' ';
$requirement['severity'] = REQUIREMENT_ERROR;
$fileinfo_enabled = FALSE;
}
// Test UNIX 'file' command engine.
if (($fileunix_enabled = $config
->get('unixfile.enable')) && !$mimedetect_service
->checkUnixfile($config
->get('unixfile.binary'), $magic_file, $msg)) {
$requirement['description'] = $msg . ' ' . t("UNIX 'file' command detection engine disabled.") . ' ';
$requirement['severity'] = REQUIREMENT_ERROR;
$fileunix_enabled = FALSE;
}
else {
$filebin_version = $msg;
}
// Enabled engines + default.
$enabled_engines = '';
$enabled_engines .= $fileinfo_enabled ? 'fileinfo, ' : '';
$enabled_engines .= $fileunix_enabled ? 'UNIX file command v. ' . $filebin_version . ', ' : '';
$enabled_engines .= 'filename extension';
$requirement['value'] = $enabled_engines;
// No real MIME detection engine enabled.
if ($fileinfo_enabled + $fileunix_enabled == 0 && $requirement['severity'] == REQUIREMENT_OK) {
$requirement['description'] = t("MimeDetect is using the browser supplied filename for file extension lookups. It is strongly recommended that you install and configure the PHP Fileinfo Extension or the UNIX 'file' command to provide more accurate sever-side mime type detection.");
$requirement['severity'] = REQUIREMENT_WARNING;
}
return [
'mimetype' => $requirement,
];
}
Functions
Name | Description |
---|---|
mimedetect_requirements | Implements hook_requirements(). |