code: protected function getRuleset($sourceFileName, $targetFileName, \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUser = null)
      {
          $ret = [];
  
          // Make file name relative and extract the extension
          $relTargetFileName = substr($targetFileName, strlen(PATH_site));
          $fileExtension = strtolower(substr($targetFileName, strrpos($targetFileName, '.') + 1));
  
          $beGroups = $backendUser !== null ? array_keys($GLOBALS['BE_USER']->userGroups) : [];
          $fileSize = is_file($sourceFileName)
              ? filesize($sourceFileName)
              : -1;    // -1 is a special value so that file size is not taken into account (yet)
  
          // Try to find a matching ruleset
          foreach ($this->rulesets as $ruleset) {
              if (!is_array($ruleset['file_types'])) {
                  // Default general settings do not include any watched image types
                  continue;
              }
              if (count($ruleset['usergroup']) > 0 && (
                      $backendUser === null ||
                      count(array_intersect($ruleset['usergroup'], $beGroups)) == 0)
              ) {
                  // Backend user is not member of a group configured for the current rule set
                  continue;
              }
              $processFile = false;
              foreach ($ruleset['directories'] as $directoryPattern) {
                  $processFile |= preg_match($directoryPattern, $relTargetFileName);
              }
              $processFile &= in_array($fileExtension, $ruleset['file_types']);
              $processFile &= $fileSize === -1 || ($fileSize > $ruleset['threshold']);
              if ($processFile) {
                  $ret = $ruleset;
                  break;
              }
          }
          return $ret;
      }
docs: Returns the rule set that applies to a given file for a given backend user (or null
  if using scheduler task).
  
  @param string $sourceFileName
  @param string $targetFileName
  @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUser
  @return array