From 47113a06efd11d2de4a47bc8503cd706dc3a37b5 Mon Sep 17 00:00:00 2001 From: Matt Peel Date: Tue, 21 Nov 2023 22:56:49 +1300 Subject: [PATCH] NEW: Add the ability to specify the MimeTypeDetector for the LocalFilesystemAdapter --- src/Flysystem/AssetAdapter.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Flysystem/AssetAdapter.php b/src/Flysystem/AssetAdapter.php index 41c6b8a2..a249596d 100644 --- a/src/Flysystem/AssetAdapter.php +++ b/src/Flysystem/AssetAdapter.php @@ -36,6 +36,16 @@ class AssetAdapter extends LocalFilesystemAdapter */ private static $default_server = 'apache'; + /** + * Default mime type detector to use. If not defined, the default mime type detector from Flysystem will be used. + * If you want to define one, this must be the name of a class that implements the interface + * League\MimeTypeDetection\MimeTypeDetector + * + * @config + * @var string + */ + private static $default_mime_type_detector; + /** * Config compatible permissions configuration * @@ -68,7 +78,19 @@ public function __construct($root = null, $writeFlags = LOCK_EX, $linkHandling = $permissions = PortableVisibilityConverter::fromArray( $this->normalisePermissions($this->config()->get('file_permissions')) ); - parent::__construct($root, $permissions, $writeFlags, $linkHandling); + + // Get the mimetype detector from config, if defined, and ensure it's valid + $mimeTypeDetector = null; + + if ($mimeTypeDetectorClassName = $this->config()->get('default_mime_type_detector')) { + $mimeTypeDetector = Injector::inst()->get($mimeTypeDetectorClassName); + + if (!$mimeTypeDetector instanceof MimeTypeDetector) { + $mimeTypeDetector = null; + } + } + + parent::__construct($root, $permissions, $writeFlags, $linkHandling, $mimeTypeDetector); // Configure server $this->configureServer();