give
/
vendor
/
vendor-prefixed
/
stellarwp
/
admin-notices
/
src
/
ValueObjects
/
NoticeUrgency.php
NoticeLocation.php
1 year ago
NoticeUrgency.php
1 year ago
ScreenCondition.php
1 year ago
Script.php
1 year ago
Style.php
1 year ago
UserCapability.php
1 year ago
NoticeUrgency.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Vendors\StellarWP\AdminNotices\ValueObjects; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | |
| 7 | /** |
| 8 | * A value object representing the urgency of a notice. |
| 9 | * |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | class NoticeUrgency |
| 13 | { |
| 14 | const INFO = 'info'; |
| 15 | const WARNING = 'warning'; |
| 16 | const ERROR = 'error'; |
| 17 | const SUCCESS = 'success'; |
| 18 | |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | private $urgency; |
| 23 | |
| 24 | /** |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | public static function info(): self |
| 28 | { |
| 29 | return new self(self::INFO); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @since 1.0.0 |
| 34 | */ |
| 35 | public static function warning(): self |
| 36 | { |
| 37 | return new self(self::WARNING); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @since 1.0.0 |
| 42 | */ |
| 43 | public static function error(): self |
| 44 | { |
| 45 | return new self(self::ERROR); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @since 1.0.0 |
| 50 | */ |
| 51 | public static function success(): self |
| 52 | { |
| 53 | return new self(self::SUCCESS); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public function __construct(string $urgency) |
| 60 | { |
| 61 | if (!in_array($urgency, [self::INFO, self::WARNING, self::ERROR, self::SUCCESS])) { |
| 62 | throw new InvalidArgumentException('Invalid urgency'); |
| 63 | } |
| 64 | |
| 65 | $this->urgency = $urgency; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @since 1.0.0 |
| 70 | */ |
| 71 | public function __toString(): string |
| 72 | { |
| 73 | return $this->urgency; |
| 74 | } |
| 75 | } |
| 76 |