| | string $time, |
| | bool $isDir, |
| | - string $mediaType |
| | + callable $isMediaType |
| | ): void; |
| | } |
 |
| | string $time, |
| | bool $isDir, |
| | - string $mediaType |
| | + callable $isMediaType |
| | ): void { |
| | - $iconClass = $this->getIconClass($isDir, $mediaType); |
| | + $iconClass = $this->getIconClass($isDir, $isMediaType); |
| | |
| | $url = '?repo=' . urlencode($this->repoSafeName) . '&hash=' . $sha; |
 |
| | * Maps media types to FontAwesome 6 icon classes. |
| | */ |
| | - private function getIconClass(bool $isDir, string $mime): string { |
| | + private function getIconClass(bool $isDir, callable $isMediaType): string { |
| | if ($isDir) { |
| | return 'fa-folder'; |
| | } |
| | |
| | // Explicit Mime Matches |
| | - if ($mime === 'application/pdf') return 'fa-file-pdf'; |
| | + if ($isMediaType('application/pdf')) return 'fa-file-pdf'; |
| | |
| | // Archives |
| | - if (in_array($mime, [ |
| | + $archives = [ |
| | 'application/zip', 'application/x-tar', 'application/gzip', |
| | 'application/x-bzip2', 'application/vnd.rar', 'application/x-7z-compressed' |
| | - ])) { |
| | - return 'fa-file-archive'; |
| | + ]; |
| | + foreach ($archives as $archive) { |
| | + if ($isMediaType($archive)) return 'fa-file-archive'; |
| | } |
| | |
| | // Broad Categories (based on prefix) |
| | - if (str_starts_with($mime, 'image/')) return 'fa-file-image'; |
| | - if (str_starts_with($mime, 'audio/')) return 'fa-file-audio'; |
| | - if (str_starts_with($mime, 'video/')) return 'fa-file-video'; |
| | + if ($isMediaType('image/')) return 'fa-file-image'; |
| | + if ($isMediaType('audio/')) return 'fa-file-audio'; |
| | + if ($isMediaType('video/')) return 'fa-file-video'; |
| | |
| | // Code / Text |
| | - if (str_starts_with($mime, 'text/')) return 'fa-file-code'; |
| | + if ($isMediaType('text/')) return 'fa-file-code'; |
| | |
| | // Common Application Types behaving like code/text |
| | if ( |
| | - str_contains($mime, 'javascript') || |
| | - str_contains($mime, 'json') || |
| | - str_contains($mime, 'xml') || |
| | - str_contains($mime, 'php') || |
| | - str_contains($mime, 'sh') |
| | + $isMediaType('javascript') || |
| | + $isMediaType('json') || |
| | + $isMediaType('xml') || |
| | + $isMediaType('php') || |
| | + $isMediaType('sh') |
| | ) { |
| | return 'fa-file-code'; |