Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Initializes finfo object lazily

AuthorDave Jarvis <email>
Date2026-02-21 00:30:20 GMT-0800
Commitcb62633c31126c00c40482da20d6daa083bbc981
Parentef7a6e8
File.php
string $contents = ''
) {
- self::$finfo ??= new finfo( FILEINFO_MIME_TYPE );
-
$this->name = $name;
$this->sha = $sha;
default => self::ICON_FILE,
});
+ }
+
+ private static function fileinfo(): finfo {
+ return self::$finfo ??= new finfo( FILEINFO_MIME_TYPE );
}
private function detectMediaType( string $buffer ): string {
return $buffer === ''
? self::MEDIA_EMPTY
- : (self::$finfo->buffer( substr( $buffer, 0, 256 ) )
+ : (self::fileinfo()->buffer( substr( $buffer, 0, 128 ) )
?: self::MEDIA_OCTET);
}
Delta5 lines added, 3 lines removed, 2-line increase