Total Complexity | 11 |
Total Lines | 95 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class Notices |
||
16 | { |
||
17 | /** |
||
18 | * The notices list. |
||
19 | * |
||
20 | * @var array |
||
21 | * @since 1.0 |
||
22 | * @static |
||
23 | */ |
||
24 | private static $notices = []; |
||
25 | |||
26 | /** |
||
27 | * @access private |
||
28 | * @since 1.0 |
||
29 | */ |
||
30 | private function __construct() |
||
31 | { |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Get all notices. |
||
36 | * |
||
37 | * @return array |
||
38 | * @since 1.0 |
||
39 | * @static |
||
40 | */ |
||
41 | public static function getNotices() |
||
42 | { |
||
43 | return self::$notices; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get a notice. |
||
48 | * |
||
49 | * @return object |
||
50 | * @since 1.0 |
||
51 | * @static |
||
52 | */ |
||
53 | public static function getNotice($code) |
||
54 | { |
||
55 | if (self::isExists($code)) { |
||
56 | return self::$notices[$code]; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Whether a given notice is exists. |
||
62 | * |
||
63 | * @return bool |
||
64 | * @since 1.0 |
||
65 | * @static |
||
66 | */ |
||
67 | public static function isExists($code) |
||
68 | { |
||
69 | return isset(self::$notices[$code]); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Add a new notice. |
||
74 | * |
||
75 | * @return bool |
||
76 | * @since 1.0 |
||
77 | * @static |
||
78 | */ |
||
79 | public static function addNotice($code, $msg, $type = 'warning') |
||
80 | { |
||
81 | if (! $code || self::isExists($code)) { |
||
82 | return false; |
||
83 | } |
||
84 | |||
85 | self::$notices[$code] = (object) [ |
||
86 | 'code' => $code, |
||
87 | 'type' => $type, |
||
88 | 'msg' => $msg, |
||
89 | ]; |
||
90 | |||
91 | return true; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Remove an existing notice. |
||
96 | * |
||
97 | * @return void |
||
98 | * @since 1.0 |
||
99 | * @static |
||
100 | */ |
||
101 | public static function removeNotice($code) |
||
110 | } |
||
111 | } |
||
112 |