| | private const MEDIA_OCTET = 'application/octet-stream'; |
| | private const MEDIA_PDF = 'application/pdf'; |
| | - private const MEDIA_TEXT_PRE = 'text/'; |
| | + private const MEDIA_TEXT = 'text/'; |
| | private const MEDIA_SVG = 'image/svg'; |
| | + private const MEDIA_APP_TEXT = [ |
| | + 'application/javascript', |
| | + 'application/json', |
| | + 'application/xml', |
| | + 'application/x-httpd-php', |
| | + 'application/x-sh' |
| | + ]; |
| | |
| | private const ARCHIVE_EXT = [ |
 |
| | ? self::MEDIA_EMPTY |
| | : ((new finfo( FILEINFO_MIME_TYPE )) |
| | - ->buffer( substr( $buffer, 0, 512 ) ) |
| | + ->buffer( substr( $buffer, 0, 256 ) ) |
| | ?: self::MEDIA_OCTET); |
| | } |
| | |
| | private function detectCategory( string $filename ): string { |
| | $main = explode( '/', $this->mediaType )[0]; |
| | $main = $this->isArchive( $filename ) || |
| | str_contains( $this->mediaType, 'compressed' ) |
| | ? self::CAT_ARCHIVE |
| | + : $main; |
| | + |
| | + $main = $main !== self::CAT_ARCHIVE && |
| | + $this->isMediaTypeText() |
| | + ? 'text' |
| | : $main; |
| | |
 |
| | private function detectBinary(): bool { |
| | return $this->mediaType !== self::MEDIA_EMPTY && |
| | - !str_starts_with( $this->mediaType, self::MEDIA_TEXT_PRE ) && |
| | + !$this->isMediaTypeText() && |
| | !str_contains( $this->mediaType, self::MEDIA_SVG ); |
| | + } |
| | + |
| | + private function isMediaTypeText(): bool { |
| | + return str_starts_with( $this->mediaType, self::MEDIA_TEXT ) || |
| | + in_array( $this->mediaType, self::MEDIA_APP_TEXT, true ); |
| | } |
| | |