| Conditions | 6 |
| Paths | 6 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 30 | public function guess(string $path): string |
||
| 31 | { |
||
| 32 | if (!is_file($path)) { |
||
| 33 | throw new FileNotFoundException($path); |
||
| 34 | } |
||
| 35 | |||
| 36 | if (!is_readable($path)) { |
||
| 37 | throw new AccessDeniedException($path); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!self::isSupported()) { |
||
| 41 | return ''; |
||
| 42 | } |
||
| 43 | |||
| 44 | $return = 1; |
||
| 45 | ob_start(); |
||
| 46 | passthru(sprintf('file -b --mime %s 2>/dev/null', escapeshellarg($path)), $return); |
||
| 47 | if ($return > 0) { |
||
| 48 | ob_end_clean(); |
||
| 49 | return ''; |
||
| 50 | } |
||
| 51 | |||
| 52 | $type = trim(ob_get_clean()); |
||
| 53 | if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) { |
||
| 54 | return ''; |
||
| 55 | } |
||
| 56 | |||
| 57 | return $match[1]; |
||
| 58 | } |
||
| 59 | } |