| 1 |
<?php |
| 2 |
/** |
| 3 |
* Extends MainWP Exception |
| 4 |
* |
| 5 |
* Grabs $extra and stores it in $messageExtra. |
| 6 |
* |
| 7 |
* @package MainWP/Dashboard |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class MainWP_Exception |
| 19 |
* |
| 20 |
* @package MainWP\Dashboard |
| 21 |
*/ |
| 22 |
class MainWP_Exception extends \Exception { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 23 |
|
| 24 |
/** |
| 25 |
* Protected variable to hold the extra messages. |
| 26 |
* |
| 27 |
* @var string Error messages. |
| 28 |
*/ |
| 29 |
protected $messageExtra; |
| 30 |
|
| 31 |
/** |
| 32 |
* Protected variable to hold the Error Code. |
| 33 |
* |
| 34 |
* @var string Error Code. |
| 35 |
*/ |
| 36 |
protected $errorCode; |
| 37 |
|
| 38 |
/** |
| 39 |
* Protected variable to hold the extra data. |
| 40 |
* |
| 41 |
* @var array data. |
| 42 |
*/ |
| 43 |
protected $data; |
| 44 |
|
| 45 |
/** |
| 46 |
* MainWP_Exception constructor. |
| 47 |
* |
| 48 |
* Grab Exception Message upon creation of the object. |
| 49 |
* |
| 50 |
* @param mixed $message Exception message. |
| 51 |
* @param null $extra Any extra Errors. |
| 52 |
* @param string $errCode Errors code. |
| 53 |
*/ |
| 54 |
public function __construct( $message, $extra = null, $errCode = '' ) { |
| 55 |
parent::__construct( $message ); |
| 56 |
$this->messageExtra = $extra; // escape in get method. |
| 57 |
$this->errorCode = esc_html( $errCode ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Method get_message_extra() |
| 62 |
* |
| 63 |
* @param bool $escape_msg Exception message. |
| 64 |
* |
| 65 |
* @return $messageExtra Extra messages. |
| 66 |
*/ |
| 67 |
public function get_message_extra( $escape_msg = true ) { |
| 68 |
return $escape_msg ? esc_html( wp_strip_all_tags( $this->messageExtra ) ) : $this->messageExtra; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Method get_message_error_code() |
| 73 |
* |
| 74 |
* @return string $errorCode Errors code. |
| 75 |
*/ |
| 76 |
public function get_message_error_code() { |
| 77 |
return $this->errorCode; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Method set_data() |
| 82 |
* |
| 83 |
* @param mixed $data Addition data. |
| 84 |
*/ |
| 85 |
public function set_data( $data ) { |
| 86 |
$this->data = $data; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Method get_data() |
| 91 |
* |
| 92 |
* @return $data Addition data. |
| 93 |
*/ |
| 94 |
public function get_data() { |
| 95 |
return $this->data; |
| 96 |
} |
| 97 |
} |
| 98 |
|