Skip to content

Commit

Permalink
[REF] Switch to using a non abondoned library for getting a mapping o…
Browse files Browse the repository at this point in the history
…f mimetpyes to extensions
  • Loading branch information
seamuslee001 committed Jan 31, 2020
1 parent fd4aac2 commit 0b2b2ef
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 57 deletions.
12 changes: 4 additions & 8 deletions CRM/Utils/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use MimeTyper\Repository\ExtendedRepository;

/**
* class to provide simple static functions for file objects
*/
Expand Down Expand Up @@ -1083,14 +1085,8 @@ public static function isValidFileName($fileName = NULL) {
* @return array
*/
public static function getAcceptableExtensionsForMimeType($mimeType = NULL) {
$mapping = \MimeType\Mapping::$types;
$extensions = [];
foreach ($mapping as $extension => $type) {
if ($mimeType == $type) {
$extensions[] = $extension;
}
}
return $extensions;
$mimeRepostory = new ExtendedRepository();
return $mimeRepostory->findExtensions($mimeType);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"psr/simple-cache": "~1.0.1",
"cweagans/composer-patches": "~1.0",
"pear/log": "1.13.1",
"katzien/php-mime-type": "2.1.0",
"adrienrn/php-mimetyper": "0.2.2",
"civicrm/composer-downloads-plugin": "^2.0",
"league/csv": "^9.2",
"tplaner/when": "~3.0.0",
Expand Down
142 changes: 95 additions & 47 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Utils/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testPathToExtension($path, $expectedExtension) {

public function mimeTypeToExtension() {
$cases = [];
$cases[] = ['text/plain', ['txt', 'text', 'conf', 'def', 'list', 'log', 'in']];
$cases[] = ['text/plain', ['txt', 'text', 'conf', 'def', 'list', 'log', 'in', 'ini']];
$cases[] = ['image/jpeg', ['jpeg', 'jpg', 'jpe']];
$cases[] = ['image/png', ['png']];
return $cases;
Expand Down

0 comments on commit 0b2b2ef

Please sign in to comment.