You are here

public function MimeDetectService::__construct in MimeDetect 8

Construct the MimeDetectService object.

Parameters

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The factory for configuration objects.

\Drupal\Core\File\FileSystemInterface $file_system: File system helpers to operate on files.

\Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser: The MIME type guesser instance to use.

\Drupal\mimedetect\MimeDetectPluginManager $mime_detector_plugin: The MIME detect plugin manager.

File

src/MimeDetectService.php, line 62

Class

MimeDetectService
MimeDetect service.

Namespace

Drupal\mimedetect

Code

public function __construct(ConfigFactoryInterface $config_factory, FileSystemInterface $file_system, MimeTypeGuesserInterface $mime_type_guesser, MimeDetectPluginManager $mime_detector_plugin) {
  $this->fileSystem = $file_system;
  $this->mimeTypeGuesser = $mime_type_guesser;
  $this->mimeDetectorPluginManager = $mime_detector_plugin;
  $config = $config_factory
    ->get('mimedetect.settings');

  // Enable fileinfo engine.
  if ($config
    ->get('fileinfo.enable') && $this
    ->checkFileinfo($config
    ->get('magicfile'))) {
    $this->finfo = new \finfo(FILEINFO_MIME_TYPE, $config
      ->get('magicfile'));
  }

  // Enable UNIX 'file' command engine.
  if ($config
    ->get('unixfile.enable') && $this
    ->checkUnixfile($config
    ->get('unixfile.binary'), $config
    ->get('magicfile'))) {
    $this->unixfilecmd = $config
      ->get('unixfile.binary') . ' --brief --mime' . (!empty($config
      ->get('magicfile')) ? ' --magic-file=' . escapeshellarg($config
      ->get('magicfile')) : '') . ' ';
  }
}