You are here

public function Scanner::isScannable in ClamAV 8

Same name and namespace in other branches
  1. 2.x src/Scanner.php \Drupal\clamav\Scanner::isScannable()

Check whether a specific file should be scanned by ClamAV.

Specific files can be excluded from anti-virus scanning, such as:

  • Image files
  • Large files that might take a long time to scan
  • Files uploaded by trusted administrators
  • Viruses, intended to be deliberately uploaded to a virus database

Files can be excluded from the scans by implementing hook_clamav_file_is_scannable().

Return value

boolean TRUE if a file should be scanned by the anti-virus service.

See also

hook_clamav_file_is_scannable().

File

src/Scanner.php, line 107

Class

Scanner
Service class for the ClamAV scanner instance.

Namespace

Drupal\clamav

Code

public function isScannable(FileInterface $file) {

  // Check whether this stream-wrapper scheme is scannable.
  if (!empty($file->destination)) {
    $scheme = \Drupal::service('stream_wrapper_manager')
      ->getScheme($file->destination);
  }
  else {
    $scheme = \Drupal::service('stream_wrapper_manager')
      ->getScheme($file
      ->getFileUri());
  }
  $scannable = self::isSchemeScannable($scheme);

  // Iterate each module implementing hook_clamav_file_is_scannable().
  // Modules that do not wish to affact the result should return
  // FILE_SCANNABLE_IGNORE.
  foreach (\Drupal::moduleHandler()
    ->getImplementations('clamav_file_is_scannable') as $module) {
    $result = \Drupal::moduleHandler()
      ->invoke($module, 'clamav_file_is_scannable', array(
      $file,
    ));
    if ($result !== self::FILE_SCANNABLE_IGNORE) {
      $scannable = $result;
    }
  }
  return $scannable;
}