original_string: public static function fileIcon($mime, $iconsDirectory = false)
      {
          if (!$iconsDirectory) {
              $iconsDirectory = Plugin::path('Field') . 'webroot/img/file-icons/';
          }
  
          // If there's an icon matching the exact mimetype, go for it.
          $dashedMime = strtr($mime, ['/' => '-']);
          if (is_readable("{$iconsDirectory}{$dashedMime}.png")) {
              return "{$dashedMime}.png";
          }
  
          // For a few mimetypes, we can "manually" map to a generic icon.
          $genericMime = (string)static::fileIconMap($mime);
          if ($genericMime && is_readable("{$iconsDirectory}{$genericMime}.png")) {
              return "{$genericMime}.png";
          }
  
          // Use generic icons for each category that provides such icons.
          if (preg_match('/^(audio|image|text|video)\//', $mime, $matches)) {
              if (is_readable("{$iconsDirectory}{$matches[1]}-x-generic.png")) {
                  return "{$matches[1]}-x-generic.png";
              }
          }
  
          if (is_readable("{$iconsDirectory}/application-octet-stream.png")) {
              return 'application-octet-stream.png';
          }
  
          return false;
      }
code: public static function fileIcon($mime, $iconsDirectory = false)
      {
          if (!$iconsDirectory) {
              $iconsDirectory = Plugin::path('Field') . 'webroot/img/file-icons/';
          }
  
          // If there's an icon matching the exact mimetype, go for it.
          $dashedMime = strtr($mime, ['/' => '-']);
          if (is_readable("{$iconsDirectory}{$dashedMime}.png")) {
              return "{$dashedMime}.png";
          }
  
          // For a few mimetypes, we can "manually" map to a generic icon.
          $genericMime = (string)static::fileIconMap($mime);
          if ($genericMime && is_readable("{$iconsDirectory}{$genericMime}.png")) {
              return "{$genericMime}.png";
          }
  
          // Use generic icons for each category that provides such icons.
          if (preg_match('/^(audio|image|text|video)\//', $mime, $matches)) {
              if (is_readable("{$iconsDirectory}{$matches[1]}-x-generic.png")) {
                  return "{$matches[1]}-x-generic.png";
              }
          }
  
          if (is_readable("{$iconsDirectory}/application-octet-stream.png")) {
              return 'application-octet-stream.png';
          }
  
          return false;
      }
code_tokens: public static function fileIcon ( $ mime , $ iconsDirectory = false ) { if ( ! $ iconsDirectory ) { $ iconsDirectory = Plugin :: path ( 'Field' ) . 'webroot/img/file-icons/' ; } // If there's an icon matching the exact mimetype, go for it. $ dashedMime = strtr ( $ mime , [ '/' => '-' ] ) ; if ( is_readable ( "{$iconsDirectory}{$dashedMime}.png" ) ) { return "{$dashedMime}.png" ; } // For a few mimetypes, we can "manually" map to a generic icon. $ genericMime = ( string ) static :: fileIconMap ( $ mime ) ; if ( $ genericMime && is_readable ( "{$iconsDirectory}{$genericMime}.png" ) ) { return "{$genericMime}.png" ; } // Use generic icons for each category that provides such icons. if ( preg_match ( '/^(audio|image|text|video)\//' , $ mime , $ matches ) ) { if ( is_readable ( "{$iconsDirectory}{$matches[1]}-x-generic.png" ) ) { return "{$matches[1]}-x-generic.png" ; } } if ( is_readable ( "{$iconsDirectory}/application-octet-stream.png" ) ) { return 'application-octet-stream.png' ; } return false ; }
docstring: Creates a path to the icon for a file mime.
  
  @param string $mime File mime type
  @param mixed $iconsDirectory A path to a directory of icons to be used for
  files. Defaults to built-in icons directory (Field/webroot/img/file-icons/)
  @return mixed A string for the icon file name, or false if an appropriate
  icon could not be found
docstring_tokens: Creates a path to the icon for a file mime .