1 | <?php |
||
17 | class ExtensionMimeTypeGuesser |
||
18 | { |
||
19 | /** |
||
20 | * @var array Map of extensions to MIME types. |
||
21 | */ |
||
22 | private $map; |
||
23 | |||
24 | /** |
||
25 | * @var string Fallback MIME type if it can't be determined via the extension. |
||
26 | */ |
||
27 | private $fallbackType = 'application/octet-stream'; |
||
28 | |||
29 | /** |
||
30 | * Constructor. |
||
31 | * |
||
32 | * @param TypeMapInterface[] $typeMaps |
||
33 | */ |
||
34 | 6 | public function __construct(array $typeMaps = null) |
|
42 | |||
43 | /** |
||
44 | * Returns the MIME type for a given file extension. |
||
45 | * For unknown extensions, "application/octet-stream" is returned. |
||
46 | * |
||
47 | * @param string $extension |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 6 | public function guess($extension) |
|
59 | |||
60 | /** |
||
61 | * Returns the default type maps. |
||
62 | * |
||
63 | * @return TypeMapInterface[] |
||
64 | */ |
||
65 | 5 | public static function getDefaultTypeMaps() |
|
79 | |||
80 | /** |
||
81 | * Builds a lookup array from the type maps. |
||
82 | * |
||
83 | * @param TypeMapInterface[] $typeMaps |
||
84 | * |
||
85 | * @return array flat map array with the file extension as key and the MIME type as value |
||
86 | */ |
||
87 | 6 | private function buildMap($typeMaps) |
|
105 | } |
||
106 |