| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\FileinfoException; |
| 6 |
|
| 7 |
/** |
| 8 |
* This function closes the resource opened by finfo_open. |
| 9 |
* |
| 10 |
* @param resource $finfo Fileinfo resource returned by finfo_open. |
| 11 |
* @throws FileinfoException |
| 12 |
* |
| 13 |
*/ |
| 14 |
function finfo_close($finfo): void |
| 15 |
{ |
| 16 |
error_clear_last(); |
| 17 |
$result = \finfo_close($finfo); |
| 18 |
if ($result === false) { |
| 19 |
throw FileinfoException::createFromPhpError(); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
* Procedural style |
| 26 |
* |
| 27 |
* Object oriented style (constructor): |
| 28 |
* |
| 29 |
* This function opens a magic database and returns its resource. |
| 30 |
* |
| 31 |
* @param int $options One or disjunction of more Fileinfo |
| 32 |
* constants. |
| 33 |
* @param string $magic_file Name of a magic database file, usually something like |
| 34 |
* /path/to/magic.mime. If not specified, the |
| 35 |
* MAGIC environment variable is used. If the |
| 36 |
* environment variable isn't set, then PHP's bundled magic database will |
| 37 |
* be used. |
| 38 |
* |
| 39 |
* Passing NULL or an empty string will be equivalent to the default |
| 40 |
* value. |
| 41 |
* @return resource (Procedural style only) |
| 42 |
* Returns a magic database resource on success. |
| 43 |
* @throws FileinfoException |
| 44 |
* |
| 45 |
*/ |
| 46 |
function finfo_open(int $options = FILEINFO_NONE, string $magic_file = "") |
| 47 |
{ |
| 48 |
error_clear_last(); |
| 49 |
$result = \finfo_open($options, $magic_file); |
| 50 |
if ($result === false) { |
| 51 |
throw FileinfoException::createFromPhpError(); |
| 52 |
} |
| 53 |
return $result; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* Returns the MIME content type for a file as determined by using |
| 59 |
* information from the magic.mime file. |
| 60 |
* |
| 61 |
* @param string $filename Path to the tested file. |
| 62 |
* @return string Returns the content type in MIME format, like |
| 63 |
* text/plain or application/octet-stream. |
| 64 |
* @throws FileinfoException |
| 65 |
* |
| 66 |
*/ |
| 67 |
function mime_content_type(string $filename): string |
| 68 |
{ |
| 69 |
error_clear_last(); |
| 70 |
$result = \mime_content_type($filename); |
| 71 |
if ($result === false) { |
| 72 |
throw FileinfoException::createFromPhpError(); |
| 73 |
} |
| 74 |
return $result; |
| 75 |
} |
| 76 |
|