Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git
File.php
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 );
}

Detects application text media types

Author Dave Jarvis <email>
Date 2026-02-18 20:48:42 GMT-0800
Commit f1652ce8f6870fbc5090adfb3e7043ad6bb85329
Parent 78a169d
Delta 20 lines added, 3 lines removed, 17-line increase