| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\ErrorfuncException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Sends an error message to the web server's error log or to a file. |
| 9 |
* |
| 10 |
* @param string $message The error message that should be logged. |
| 11 |
* @param int $message_type Says where the error should go. The possible message types are as |
| 12 |
* follows: |
| 13 |
* |
| 14 |
* |
| 15 |
* error_log log types |
| 16 |
* |
| 17 |
* |
| 18 |
* |
| 19 |
* 0 |
| 20 |
* |
| 21 |
* message is sent to PHP's system logger, using |
| 22 |
* the Operating System's system logging mechanism or a file, depending |
| 23 |
* on what the error_log |
| 24 |
* configuration directive is set to. This is the default option. |
| 25 |
* |
| 26 |
* |
| 27 |
* |
| 28 |
* 1 |
| 29 |
* |
| 30 |
* message is sent by email to the address in |
| 31 |
* the destination parameter. This is the only |
| 32 |
* message type where the fourth parameter, |
| 33 |
* extra_headers is used. |
| 34 |
* |
| 35 |
* |
| 36 |
* |
| 37 |
* 2 |
| 38 |
* |
| 39 |
* No longer an option. |
| 40 |
* |
| 41 |
* |
| 42 |
* |
| 43 |
* 3 |
| 44 |
* |
| 45 |
* message is appended to the file |
| 46 |
* destination. A newline is not automatically |
| 47 |
* added to the end of the message string. |
| 48 |
* |
| 49 |
* |
| 50 |
* |
| 51 |
* 4 |
| 52 |
* |
| 53 |
* message is sent directly to the SAPI logging |
| 54 |
* handler. |
| 55 |
* |
| 56 |
* |
| 57 |
* |
| 58 |
* |
| 59 |
* |
| 60 |
* @param string|null $destination The destination. Its meaning depends on the |
| 61 |
* message_type parameter as described above. |
| 62 |
* @param string|null $extra_headers The extra headers. It's used when the message_type |
| 63 |
* parameter is set to 1. |
| 64 |
* This message type uses the same internal function as |
| 65 |
* mail does. |
| 66 |
* |
| 67 |
* @throws ErrorfuncException |
| 68 |
* |
| 69 |
*/ |
| 70 |
function error_log(string $message, int $message_type = 0, ?string $destination = null, ?string $extra_headers = null): void |
| 71 |
{ |
| 72 |
error_clear_last(); |
| 73 |
if ($extra_headers !== null) { |
| 74 |
$result = \error_log($message, $message_type, $destination, $extra_headers); |
| 75 |
} elseif ($destination !== null) { |
| 76 |
$result = \error_log($message, $message_type, $destination); |
| 77 |
} else { |
| 78 |
$result = \error_log($message, $message_type); |
| 79 |
} |
| 80 |
if ($result === false) { |
| 81 |
throw ErrorfuncException::createFromPhpError(); |
| 82 |
} |
| 83 |
} |
| 84 |
|