1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Utils;
9:
10: use Nette;
11:
12:
13: /**
14: * Mime type detector.
15: *
16: * @deprecated
17: */
18: class MimeTypeDetector
19: {
20:
21: /**
22: * Static class - cannot be instantiated.
23: */
24: final public function __construct()
25: {
26: throw new Nette\StaticClassException;
27: }
28:
29:
30: /**
31: * Returns the MIME content type of file.
32: * @param string
33: * @return string
34: */
35: public static function fromFile($file)
36: {
37: trigger_error(__METHOD__ . '() is deprecated; use finfo_file() instead.', E_USER_DEPRECATED);
38: if (!is_file($file)) {
39: throw new Nette\FileNotFoundException("File '$file' not found.");
40: }
41: $type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
42: return strpos($type, '/') ? $type : 'application/octet-stream';
43: }
44:
45:
46: /**
47: * Returns the MIME content type of file.
48: * @param string
49: * @return string
50: */
51: public static function fromString($data)
52: {
53: trigger_error(__METHOD__ . '() is deprecated; use finfo_buffer() instead.', E_USER_DEPRECATED);
54: $type = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
55: return strpos($type, '/') ? $type : 'application/octet-stream';
56: }
57:
58: }
59: