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