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