1 | <?php |
||
2 | |||
3 | namespace WebPConvert\Helpers; |
||
4 | |||
5 | use ImageMimeTypeGuesser\ImageMimeTypeGuesser; |
||
6 | |||
7 | use WebPConvert\Exceptions\InvalidInputException; |
||
8 | use WebPConvert\Exceptions\InvalidInput\TargetNotFoundException; |
||
9 | |||
10 | /** |
||
11 | * Get MimeType, results cached by path. |
||
12 | * |
||
13 | * @package WebPConvert |
||
14 | * @author Bjørn Rosell <[email protected]> |
||
15 | * @since Class available since Release 2.0.6 |
||
16 | */ |
||
17 | class MimeType |
||
18 | { |
||
19 | private static $cachedDetections = []; |
||
20 | |||
21 | /** |
||
22 | * Get mime type for image (best guess). |
||
23 | * |
||
24 | * It falls back to using file extension. If that fails too, false is returned |
||
25 | * |
||
26 | * @return string|false|null mimetype (if it is an image, and type could be determined / guessed), |
||
27 | * false (if it is not an image type that the server knowns about) |
||
28 | * or null (if nothing can be determined) |
||
29 | */ |
||
30 | 35 | public static function getMimeTypeDetectionResult($absFilePath) |
|
31 | { |
||
32 | 35 | PathChecker::checkAbsolutePathAndExists($absFilePath); |
|
33 | |||
34 | 35 | if (isset(self::$cachedDetections[$absFilePath])) { |
|
35 | return self::$cachedDetections[$absFilePath]; |
||
36 | } |
||
37 | 35 | $cachedDetections[$absFilePath] = ImageMimeTypeGuesser::lenientGuess($absFilePath); |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
38 | 35 | return $cachedDetections[$absFilePath]; |
|
39 | } |
||
40 | } |
||
41 |