|
4 | 4 |
|
5 | 5 | namespace Nowo\WordToPdfBundle\Converter; |
6 | 6 |
|
| 7 | +use finfo; |
7 | 8 | use Nowo\WordToPdfBundle\Config\ProfileResolver; |
8 | 9 | use Nowo\WordToPdfBundle\Config\ResolvedConfig; |
9 | 10 | use Nowo\WordToPdfBundle\Exception\ConversionFailedException; |
|
15 | 16 | use Throwable; |
16 | 17 |
|
17 | 18 | use function array_replace_recursive; |
| 19 | +use function class_exists; |
18 | 20 | use function filesize; |
19 | | -use function function_exists; |
20 | 21 | use function in_array; |
21 | 22 | use function is_file; |
22 | 23 | use function is_readable; |
@@ -200,15 +201,12 @@ private function assertSource(string $sourcePath, ResolvedConfig $config): void |
200 | 201 | throw new ConversionFailedException(sprintf('Source file "%s" exceeds max_source_bytes (%d > %d).', $sourcePath, $size, $config->maxSourceBytes)); |
201 | 202 | } |
202 | 203 |
|
203 | | - // Light magic check when fileinfo is available |
204 | | - if (function_exists('finfo_open')) { |
205 | | - $finfo = finfo_open(FILEINFO_MIME_TYPE); |
206 | | - if ($finfo !== false) { |
207 | | - $mime = finfo_file($finfo, $sourcePath) ?: ''; |
208 | | - finfo_close($finfo); |
209 | | - if ($mime !== '' && $mime !== 'inode/x-empty' && (str_starts_with($mime, 'text/') || str_starts_with($mime, 'image/'))) { |
210 | | - throw new UnsupportedFormatException(sprintf('File "%s" does not look like a Word document (mime: %s).', $sourcePath, $mime)); |
211 | | - } |
| 204 | + // Light magic check when fileinfo is available (OO API: finfo_close() is deprecated since PHP 8.5) |
| 205 | + if (class_exists(finfo::class)) { |
| 206 | + $finfo = new finfo(FILEINFO_MIME_TYPE); |
| 207 | + $mime = $finfo->file($sourcePath) ?: ''; |
| 208 | + if ($mime !== '' && $mime !== 'inode/x-empty' && (str_starts_with($mime, 'text/') || str_starts_with($mime, 'image/'))) { |
| 209 | + throw new UnsupportedFormatException(sprintf('File "%s" does not look like a Word document (mime: %s).', $sourcePath, $mime)); |
212 | 210 | } |
213 | 211 | } |
214 | 212 | } |
|
0 commit comments