8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44395ab commit e9c0b15Copy full SHA for e9c0b15
src/Symfony/Component/Mime/FileinfoMimeTypeGuesser.php
@@ -21,6 +21,8 @@
21
*/
22
class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
23
{
24
+ private static $finfoCache = [];
25
+
26
/**
27
* @param string|null $magicFile A magic file to use with the finfo instance
28
*
@@ -46,7 +48,9 @@ public function guessMimeType(string $path): ?string
46
48
throw new LogicException(\sprintf('The "%s" guesser is not supported.', __CLASS__));
47
49
}
50
- if (false === $finfo = new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile)) {
51
+ try {
52
+ $finfo = self::$finfoCache[$this->magicFile] ??= new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile);
53
+ } catch (\Exception) {
54
return null;
55
56
$mimeType = $finfo->file($path);
0 commit comments