66
77use Intervention \Image \Drivers \SpecializableDecoder ;
88use Intervention \Image \Exceptions \DecoderException ;
9+ use Intervention \Image \Exceptions \NotSupportedException ;
910use Intervention \Image \Interfaces \SpecializedInterface ;
1011use Intervention \Image \MediaType ;
12+ use ValueError ;
1113
1214abstract class AbstractDecoder extends SpecializableDecoder implements SpecializedInterface
1315{
1416 /**
1517 * Return media (mime) type of the file at given file path
1618 *
1719 * @throws DecoderException
20+ * @throws NotSupportedException
1821 */
1922 protected function getMediaTypeByFilePath (string $ filepath ): MediaType
2023 {
@@ -24,13 +27,18 @@ protected function getMediaTypeByFilePath(string $filepath): MediaType
2427 throw new DecoderException ('Unable to detect media (MIME) from data in file path. ' );
2528 }
2629
27- return MediaType::from ($ info ['mime ' ]);
30+ try {
31+ return MediaType::from ($ info ['mime ' ]);
32+ } catch (ValueError ) {
33+ throw new NotSupportedException ('Unsupported media type (MIME) ' . $ info ['mime ' ] . '. ' );
34+ }
2835 }
2936
3037 /**
3138 * Return media (mime) type of the given image data
3239 *
3340 * @throws DecoderException
41+ * @throws NotSupportedException
3442 */
3543 protected function getMediaTypeByBinary (string $ data ): MediaType
3644 {
@@ -40,6 +48,10 @@ protected function getMediaTypeByBinary(string $data): MediaType
4048 throw new DecoderException ('Unable to detect media (MIME) from binary data. ' );
4149 }
4250
43- return MediaType::from ($ info ['mime ' ]);
51+ try {
52+ return MediaType::from ($ info ['mime ' ]);
53+ } catch (ValueError ) {
54+ throw new NotSupportedException ('Unsupported media type (MIME) ' . $ info ['mime ' ] . '. ' );
55+ }
4456 }
4557}
0 commit comments