An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored3becfef7
<?php
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
namespace Irstea\FileUploadBundle\Utils;
/**
* Description of MimeTypeIcon
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
final class MimeTypeIcon
{
private static $icons = [
'application/x-gzip' => 'zip',
'application/vnd.oasis.opendocument.text' => 'word',
'application/vnd.oasis.opendocument.spreadsheet' => 'excel',
'application/vnd.oasis.opendocument.presentation' => 'powerpoint',
'application/vnd.oasis.opendocument.graphics' => 'image',
'application/vnd.ms-excel' => 'excel',
'application/vnd.ms-powerpoint' => 'powerpoint',
'application/msword' => 'word',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'powerpoint',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word',
'application/pdf' => 'pdf',
'application/zip' => 'archive',
'application/x-rar-compressed' => 'archive',
'application/x-gtar' => 'archive',
'application/x-gzip' => 'archive',
'application/x-tar' => 'archive'
];
/**
*
* @param string $mimeType
* @return string|null
*/
public static function getMimeTypeIcon($mimeType)
{
if(!is_string($mimeType)) {
return null;
}
if(isset(self::$icons[$mimeType])) {
return self::$icons[$mimeType];
}
$matches = [];
if(preg_match('@^(text|audio|video|image)/@', $mimeType, $matches)) {
return $matches[1];
}
return null;
}
}