Skip to content

Commit

Permalink
NEW: Add the ability to specify the MimeTypeDetector for the LocalFil…
Browse files Browse the repository at this point in the history
…esystemAdapter
  • Loading branch information
mpeel-akqa committed Nov 21, 2023
1 parent 92994a8 commit 47113a0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Flysystem/AssetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 47113a0

Please sign in to comment.