| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** Stores a message and its importance. */ |
| 9 |
class ABJ_404_Solution_WPNotice { |
| 10 |
|
| 11 |
const ERROR = 'notice-error'; |
| 12 |
const WARNING = 'notice-warning'; |
| 13 |
const SUCCESS = 'notice-success'; |
| 14 |
const INFO = 'notice-info'; |
| 15 |
|
| 16 |
/** @var string */ |
| 17 |
private $type = null; |
| 18 |
|
| 19 |
/** @var mixed */ |
| 20 |
private $message = ''; |
| 21 |
|
| 22 |
/** |
| 23 |
* @param mixed $type |
| 24 |
* @param mixed $message |
| 25 |
*/ |
| 26 |
public function __construct($type, $message) { |
| 27 |
$this->type = self::INFO; |
| 28 |
|
| 29 |
$f = abj_service('functions'); |
| 30 |
$typeStr = is_string($type) ? $type : (is_scalar($type) ? (string)$type : ''); |
| 31 |
$VALID_TYPES = array(self::ERROR, self::WARNING, self::SUCCESS, self::INFO); |
| 32 |
if (!in_array($typeStr, $VALID_TYPES)) { |
| 33 |
if ($f->strtolower($typeStr) == 'info') { |
| 34 |
$typeStr = self::INFO; |
| 35 |
} else if ($f->strtolower($typeStr) == 'warning') { |
| 36 |
$typeStr = self::WARNING; |
| 37 |
} else if ($f->strtolower($typeStr) == 'success') { |
| 38 |
$typeStr = self::SUCCESS; |
| 39 |
} else if ($f->strtolower($typeStr) == 'error') { |
| 40 |
$typeStr = self::ERROR; |
| 41 |
} else { |
| 42 |
throw new Exception("Invalid type passed to constructor (" . esc_html($typeStr) . "). Expected: " . |
| 43 |
(string)json_encode($VALID_TYPES)); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
$this->type = $typeStr; |
| 48 |
$this->message = $message; |
| 49 |
} |
| 50 |
|
| 51 |
/** @return string */ |
| 52 |
function getType(): string { |
| 53 |
return $this->type; |
| 54 |
} |
| 55 |
|
| 56 |
/** @return mixed */ |
| 57 |
function getMessage() { |
| 58 |
return $this->message; |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|